[Numpy-discussion] Creating and reshaping fortran order arrays

Travis Oliphant oliphant.travis at ieee.org
Mon Aug 14 14:01:48 EDT 2006


Travis Oliphant wrote:
> However, you can use the ndarray creation function itself to do what you 
> want:
>
> a = ndarray(shape=(2,2), dtype=int32, buffer=str, order='F')
>
> This will use the memory of the string as the new array memory.
>   
Incidentally, the new array will be read-only.  But, you can fix this in 
two ways:

1) a.flags.writeable = True

   --- This is a cheat that avoids the extra copy on pickle-load and 
let's you use strings as writeable buffers.  Don't abuse it.  It will 
disappear once Python 3k has a proper bytes type.

2) a = a.copy()


-Travis







More information about the NumPy-Discussion mailing list