[Numpy-discussion] A bug in numpy.random.shuffle?
Nathaniel Smith
njs at pobox.com
Thu Sep 5 16:27:31 EDT 2013
On Thu, Sep 5, 2013 at 9:06 PM, Charles R Harris
<charlesr.harris at gmail.com> wrote:
> This behavior is not new, it is also present in 1.6.x
>
> In [1]: x = np.zeros(5, dtype=[('n', 'S1'), ('s', 'S1')])
>
> In [2]: x['s'] = [c for c in 'abcde']
>
> In [3]: x
> Out[3]:
> array([('', 'a'), ('', 'b'), ('', 'c'), ('', 'd'), ('', 'e')],
> dtype=[('n', '|S1'), ('s', '|S1')])
>
> In [4]: x[0], x[1] = x[1], x[0]
>
> In [5]: x
> Out[5]:
> array([('', 'b'), ('', 'b'), ('', 'c'), ('', 'd'), ('', 'e')],
> dtype=[('n', '|S1'), ('s', '|S1')])
>
> In [6]: np.__version__
> Out[6]: '1.6.3.dev-3f58621'
>
> So it looks like it needs to be decided if this is a bug or not. I think the
> returned scalars should be copies of the data.
I'm not a fan of the weird behaviour where for every other dtype,
scalar indexing returns an immutable copy, but for voids it returns a
mutable view. So +1 if we can do it.
However, isn't this going to mess up stuff like
x[0]["n"] = "a"
?
-n
More information about the NumPy-Discussion
mailing list