Hi,<br><br>Did you try ravel() instead ? If a copy is not needed, it returns a 1D view of the array.<br><br>Matthieu<br><br><div><span class="gmail_quote">2007/7/18, Tom Goddard <<a href="mailto:goddard@cgl.ucsf.edu">goddard@cgl.ucsf.edu
</a>>:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Does taking a slice of a flatiter always make a copy?  That appears to<br>be the behaviour in numpy 
1.0.3.<br>For example a.flat[1:3][0] = 5 does not modify the original array a,<br>even when a is contiguous.  Is this a bug?<br><br> >>> import numpy as n<br> >>> n.version.version<br>'1.0.3'<br>
 >>> a = n.zeros((2,3), n.int32)<br> >>> a<br>array([[0, 0, 0],<br>       [0, 0, 0]])<br> >>> b = a.flat[1:3]<br> >>> b[0] = 5<br> >>> b<br>array([5, 0])<br> >>> a<br>
array([[0, 0, 0],<br>       [0, 0, 0]])<br> >>> b = None<br> >>> a<br>array([[0, 0, 0],<br>       [0, 0, 0]])<br><br>This behavior does not seem to match what is described in the Numpy book<br>(Dec 7, 2006 version), section 
3.1.3 "Other attributes", page 51:<br><br>"flat<br><br>  Returns an iterator object (numpy.flatiter) that acts like a 1-d<br>version of the array.<br>  1-d indexing works on this array and it can be passed in to most
<br>routines as<br>  an array wherein a 1-d array will be constructed from it.  The new 1-d<br>array<br>  will reference this array's data if this array is C-style contiguous,<br>otherwise,<br>  new memory will be allocated for the 1-d array, the UPDATEIFCOPY flag
<br>  will be set for the new array, and this array will have its WRITEABLE flag<br>  set FALSE until the the last reference to the new array disappears.<br>When the<br>  last reference to the new 1-d array disappears, the data will be
<br>copied over to<br>  this non-contiguous array.  This is done so that a.flat effectively<br>references the<br>  current array regardless of whether or not it is contiguous or<br>non-contiguous."<br><br>Tom Goddard
<br>UC San Francisco<br><br>_______________________________________________<br>Numpy-discussion mailing list<br><a href="mailto:Numpy-discussion@scipy.org">Numpy-discussion@scipy.org</a><br><a href="http://projects.scipy.org/mailman/listinfo/numpy-discussion">
http://projects.scipy.org/mailman/listinfo/numpy-discussion</a><br></blockquote></div><br>