I am learning NumPy (and Python) and working through some exercises regarding arrays. I had a question that came up that I could not comprehend. I understand that the following code should update the original array that b is pointed to. The code is as follows.
a = np.zeros((4,5))
b = a[1:3,0:3]
b = b + 100
print('a = ', a)
print('b = ', b)
The output is:
a = [[0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0.]]
b = [[100. 100. 100.]
[100. 100. 100.]]
Why does a not update along with b? I understand that a pointer object should update the original with edits. I'm assuming it is due to the syntax that 100 is added to b. The code below updates, as I thought, with the original array changing. What is the difference?
a = np.zeros((4,5))
b = a[1:3,0:3]
b[0, 0] = 100
print('a = ', a)
Output:
a = [[ 0. 0. 0. 0. 0.]
[100. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 0.]]