I tried to use resize
on an array in this way:
a = np.array([1,2,3,4,5,6], dtype=np.uint8)
a.resize(4,2)
print a
and the output is Ok!(I meant that there was no error). But when I run this code:
a = np.array([1,2,3,4,5,6], dtype=np.uint8).reshape(2,3)
a.resize(4,2)
print a
it gave rise to an error, saying that, ValueError: cannot resize this array: it does not own its data
My question: why after applying reshape
the ownership of array is changed? The ownership is granted to whom !? The reshape
does not create a new memory and it is performing its operation on the same array memory! So why the ownership will change?
I read np.reshape and ndarray.resize doc but I can not understand the reason. I read this post. I can check ndarray.flags
always before applying the resize
method.