1

how to get exact value when I use array? why the result is array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) but not 0.7?

overlap= np.array([0]*10)
tempi = np.zeros(10)
for i in range(10):
    for j in range(10):
        tempi[j] = 0.7;
    overlap[i] = max(tempi)
    print(max(tempi))

overlap
0

1 Answer 1

3

overlap was (implicitly) declared as an integer array. As you assign floats to positions in integer arrays, they're truncated (implicitly coerced to integers).

What you'd want to do, is declare overlap to have a dtype of float -

overlap = np.array([0] * 10, dtype=np.float)

Or,

overlap = np.array([0.] * 10)

Running this again, you get what you expect.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.