On Fri, Nov 2, 2012 at 11:16 AM, Joe Kington <span dir="ltr"><<a href="mailto:jkington@wisc.edu" target="_blank">jkington@wisc.edu</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im"><div>On Fri, Nov 2, 2012 at 9:18 AM, Neal Becker <span dir="ltr"><<a href="mailto:ndbecker2@gmail.com" target="_blank">ndbecker2@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">



I'm trying to convert some matlab code.  I see this:<br>
<br>
b(1)=[];<br>
<br>
AFAICT, this removes the first element of the array, shifting the others.<br>
<br>
What is the preferred numpy equivalent?<br>
<br>
I'm not sure if<br>
<br>
b[:] = b[1:]<br></blockquote></div></div><div><br>Unless I'm missing something, don't you just want:<br><br>    b = b[1:]<br> <br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">



<br>
is safe or not<br></blockquote><div class="gmail_quote"><br><br>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:<br>
<br>    import numpy as np<br>    <br>    a = np.arange(10)<br>    <br>    b = a[1:]<br><br>    b[3] = 1000<br>    <br>    print a<br>    print b<br><br>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 
correctly, anyway...) <br></div></blockquote><div><br>AFAIK that's correct. The closest thing to Matlab's semantics would probably "b = b[1:].copy()".<br><br>b[:] = b[1:] would probably result in an error, as the RHS has a first-dimension shape one less than the LHS.<br>
<br>David<br></div></div></div>