[Numpy-discussion] Non-writeable default for numpy.ndarray

Francesc Altet faltet at carabos.com
Fri Sep 29 11:44:06 CDT 2006


A Divendres 29 Setembre 2006 18:12, Tim Hochberg va escriure:
> It's not that the it's being built from ndarray, it's that the buffer
> that you are passing it is read only. In fact, I'd argue that allowing
> the writeable flag to be set to True in this case is actually a bug.
>
> Consider this slightly modified example:
>      >>> a = "12345"*4
>      >>> f4=numpy.ndarray(buffer=a, dtype="f4", shape=3)
>      >>> f4[2] = 99
>
>     Traceback (most recent call last):
>       File "<stdin>", line 1, in ?
>     RuntimeError: array is not writeable
>
>      >>> f4.flags.writeable = True
>      >>> a
>
>     '12345123451234512345'
>
>      >>> f4.flags.writeable = True
>      >>> f4[2] = 99
>      >>> a
>
>     '12345123\x00\x00\xc6B34512345'
>
> The original, *immutable* string has been mutated. This could get you
> into real trouble in certain situations.

I see. Thanks for the explanation.

-- 
>0,0<   Francesc Altet     http://www.carabos.com/
V   V   Cárabos Coop. V.   Enjoy Data
 "-"




More information about the Numpy-discussion mailing list