I am creating an array with linspace:
>> a = np.linspace(0, 4, 9)
>> a
>> array([0. , 0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. ])
I am resizing it succesfully as below:
>> a.resize(3, 3)
>> a
>> array([[0. , 0.5, 1. ],
[1.5, 2. , 2.5],
[3. , 3.5, 4. ]])
However, when I try to resize it as below:
a.resize(4, 2, refcheck=False)
This gives me the following error:
ValueError: cannot resize this array: it does not own its data
When I create the same value array and resize it, array is resized succesfully:
>> b = np.array([0. , 0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. ])
>> b.resize(4, 2, refcheck=False)
>> b
>> array([[0. , 0.5],
[1. , 1.5],
[2. , 2.5],
[3. , 3.5]])
Both of a
and b
are numpy.ndarray
My question: Why does resize()
give this error when the array is created with linspace
? When resized with 3x3 (and so used all elements of the array), it does not complain about ownership but why does it complain with 4x2 even if I use refcheck=False
option?
I read the docs about linspace
and resize
but cannot find an answer about the reason.