[Numpy-discussion] Deserialized arrays with base mutate strings

Pauli Virtanen pav+sp@iki...
Wed Sep 23 02:37:55 CDT 2009

Wed, 23 Sep 2009 09:15:44 +0200, Hrvoje Niksic wrote:
> Numpy arrays with the "base" property are deserialized as arrays
> pointing to a storage contained within a Python string.  This is a
> problem since such arrays are mutable and can mutate existing strings.
> Here is how to create one:

Please file a bug ticket in the Trac, thanks!

Here is a simpler way, although one more difficult to accidentally:

>>> a = numpy.frombuffer("A", dtype='S1')
>>> a.flags.writeable = True
>>> b = "A"
>>> a[0] = "B"
>>> b

Pauli Virtanen

More information about the NumPy-Discussion mailing list