I have a small array data that undergoes a reshape and a copy
data = np.array([77, 115, 137, 89, 42, 107, 54, 256])
subset = data[:4].reshape(2,2)
newdata = data[4:].copy()
subset[-1,-1] = 0
newdata[1] = 0
print(data)
print(subset)
print(newdata)
Seems pretty simple. My assumption for this is that I would get the following outputs
data = array([ 77, 115, 137, 89, 42, 107, 54, 256])
subset = array([[ 77, 115],
[137, 0]])
newdata = array([ 42, 0, 54, 256])
I was correct for subset and newdata, but not data itself, which now outputs
data = np.array([77, 115, 137, 0, 42, 107, 54, 256])
The original data array has been modified from what looks like the reshape and copy and changing the 89 to 0
Any help on why and how these methods do in fact modify the original array is greatly appreciated.
Thanks!