I have to multiply two numpy arrays of different sizes (a and b), but I need to discard the first element of b before resizing.
What I see is that, if I use the full b array the resizing has no issues (but the result is not what I need, since it contains the first element of b). If I attempt to slice the first element off before applying resize I get a
ValueError: cannot resize this array: it does not own its data
Why does this happen, and how can I get around this in the most efficient way possible?
import numpy as np
# Some data
a = np.random.uniform(0., 1., 17)
# Works
b = np.array([56, 7, 343, 89, 234])
b.resize(a.shape)
d = b * a
# Does not
b = np.array([56, 7, 343, 89, 234])[1:]
b.resize(a.shape)
d = b * a
.copy():...234])[1:].copy()?copy()was not particularly efficient? This little block will be processed millions of times, so I need to make it as fast as possible. Also, why does the array not contain its data anymore after slicing?Also, why does the array not contain its data anymore after slicing?-Its a view intob, it doesn't have its own data. So, the in-place operation needed by resize won't work.anormally (or always) larger thanb? So the the resizedbis padded with 0s?,din that case will also be padded.