[Numpy-discussion] Response to PEP suggestions

Robert Kern rkern at ucsd.edu
Thu Feb 17 14:28:16 EST 2005


Fernando Perez wrote:
> Robert Kern wrote:
> 
>> Why not just do
>>
>>    b = ravel(a)
>>
>> ?
>>
>> That should work in both cases just fine.
> 
> 
> Because I thouhgt that ravel would make a copy regardless.  But I may be 
> wrong, much of this is very old code, when I was just picking up 
> Numeric.  At the time, I felt it might be best to avoid the unnecessary 
> copies if possible.

Nope.

In [1]: a = arange(8)

In [2]: a.shape = (2,4)

In [3]: a
Out[3]: NumPy array, format: long
[[0 1 2 3]
  [4 5 6 7]]

In [4]: ravel(a)[3] = 10

In [5]: a
Out[5]: NumPy array, format: long
[[ 0  1  2 10]
  [ 4  5  6  7]]

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter




More information about the NumPy-Discussion mailing list