1

I am trying to assign a assign values to the something-array using the assign operator(=) in for loop.

Below is the one with something-array initially having numbers going from 0 to 15 in its elements: [something array with its elements as numbers going from 0 to 15] (https://i.sstatic.net/a9cOg.jpg)

Below is the one with something-array initially having all its elements as zero: something array with all its elements as zeros

Why do we have different results?

I see that having different values previously as the elements of the "something-array" gives us different result from the ones that started from having zeros as its all elements previously.

I wanna know what is happening here and especially in the first case I wanna know how the calculations are done?

1

1 Answer 1

1

In numpy, zeros() method initialize the array with 0 in float whereas when you use arange() it puts the value in int datatype.

something = np.zeros(2)
for i in something:
    print(type(i))

print()

something = np.arange(2)
for i in something:
    print(type(i))

Output:

output

As you see I have printed the types of elements in the lists in both the cases, so when any other operation is performed on them it is performed according to the datatypes so the result can differ in both the cases.

I hope this explains the confusion.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.