[Numpy-discussion] A bug in numpy.random.shuffle?
Charles R Harris
charlesr.harris at gmail.com
Thu Sep 5 17:21:26 EDT 2013
On Thu, Sep 5, 2013 at 2:27 PM, Nathaniel Smith <njs at pobox.com> wrote:
> 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"
> ?
>
>
Left and right are different, but I'm not sure how the assignment op
handles that. So maybe no and maybe yes ;)
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130905/1639fb58/attachment.html>
More information about the NumPy-Discussion
mailing list