[Numpy-discussion] Creating and reshaping fortran order arrays

Travis Oliphant oliphant.travis at ieee.org
Tue Aug 15 01:01:51 CDT 2006


Fernando Perez wrote:
> Sweet! We now finally have mutable strings for Python:
>
> In [2]: astr = '\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00'
>
> In [4]: a = N.ndarray(shape=(2,2), dtype=N.int32, buffer=astr, order='F')
>
> In [5]: astr
> Out[5]: '\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00'
>
> In [6]: a.flags.writeable = True
>
> In [7]: a
> Out[7]:
> array([[0, 2],
>        [1, 3]])
>
> In [8]: a[0] = 1
>
> In [9]: astr
> Out[9]: '\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x03\x00\x00\x00'
>
>
> Guido's going to kill you on Thursday, you know ;)
>   
Don't tell him ;-)

But, if he had provided a suitable bytes type already (that was 
pickleable) we wouldn't need to do this :-)  Notice it's not writeable 
by default, so at least you have to "know what you are doing" to shoot 
yourself in the foot.

-Travis





More information about the Numpy-discussion mailing list