[Numpy-discussion] yet another trivial question
Fri Nov 2 10:16:21 CDT 2012
On Fri, Nov 2, 2012 at 9:18 AM, Neal Becker <firstname.lastname@example.org> wrote:
> I'm trying to convert some matlab code. I see this:
> AFAICT, this removes the first element of the array, shifting the others.
> What is the preferred numpy equivalent?
> I'm not sure if
> b[:] = b[1:]
Unless I'm missing something, don't you just want:
b = b[1:]
> is safe or not
It's not exactly the same as the matlab equivalent, as matlab will always
make a copy, and this will be a view of the same array. For example, if
you do something like this:
import numpy as np
a = np.arange(10)
b = a[1:]
b = 1000
You'll see that modifying "b" in-place will modify "a" as well, as "b" is
just a view into "a". This wouldn't be the case in matlab (if I remember
> NumPy-Discussion mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion