<br><br><div><span class="gmail_quote">On 8/29/07, <b class="gmail_sendername">Stefan van der Walt</b> <<a href="mailto:stefan@sun.ac.za">stefan@sun.ac.za</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi Charles<br><br>On Wed, Aug 29, 2007 at 09:42:50AM -0600, Charles R Harris wrote:<br>> Hi all,<br>><br>> This looks like a bug to me.<br>><br>> >>> a = arange(6).reshape(2,3)<br>> >>> 
a.resize((3,3))<br>> Traceback (most recent call last):<br>>   File "<stdin>", line 1, in <module><br>> ValueError: cannot resize this array:  it does not own its data<br><br>>From the docstring of 
a.resize:<br><br>    Change size and shape of self inplace.  Array must own its own memory and<br>    not be referenced by other arrays.    Returns None.</blockquote><div><br>The documentation is bogus:<br><br><span style="font-family: courier new,monospace;">
>>> a = arange(6).reshape(2,3)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">>>> a</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
array([[0, 1, 2],</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">       [3, 4, 5]])</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
>>> a.flags</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">  C_CONTIGUOUS : True</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
  F_CONTIGUOUS : False</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">  OWNDATA : False</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
  WRITEABLE : True</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">  ALIGNED : True</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
  UPDATEIFCOPY : False</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">>>> a.resize((3,2))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
>>> a</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">array([[0, 1],</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
       [2, 3],</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">       [4, 5]])</span><br> <br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
The reshaped array is a view on the original data, hence it doesn't<br>own it:<br><br>In [15]: a = N.arange(6).reshape(2,3)<br><br>In [16]: a.flags<br>Out[16]:<br>  C_CONTIGUOUS : True<br>  F_CONTIGUOUS : False<br>  OWNDATA : False
<br>  WRITEABLE : True<br>  ALIGNED : True<br>  UPDATEIFCOPY : False<br><br>> >>> a = arange(6).resize((2,3))<br>> >>> a<br>><br>> `a` has no value and no error is raised.<br><br>It is because `a` is now None.
</blockquote><div><br>This behaviour doesn't match documentation elsewhere, which is why I am raising the question.  What *should* the resize method do? It looks like it is equivalent to assigning a shape tuple to a.shape
, so why do we need it? Apart from that, the reshape method looks like it would serve for most cases.<br><br>Chuck<br></div></div><br>