I have issues understanding how Arrays work in python.
I wrote this short demo code:
from numpy import zeros
a = zeros((3), 'd')
b = zeros((2,3), 'd')
for i in range(2):
for j in range(3):
a[j] = i*j
b[i] = a
print "A: " + str(a) + "\n"
print "B: " + str(b)
The Output of this is:
A: [ 0. 1. 2.]
B: [[ 0. 0. 0.] [ 0. 1. 2.]]
So here is my question. Why isn't the output for this:
A: [ 0. 1. 2.]
B: [[ 0. 1. 2.] [ 0. 1. 2.]]
Because I made the changes in the same a and the address of the array hasn't changed.
bsublists withafor i in range(2)-> your first loop features valuei=0, settinga[j]= 0 for allj->b[0] = [0. 0. 0.]b[0]is not a sublist - it is a row in the array.b[0,:]aviewofa? Why a copy? Is b[1,:] a view or copy? What happens with lists'