[Numpy-discussion] Multiple-field indexing: view vs copy in 1.14+

josef.pktd at gmail.com josef.pktd at gmail.com
Thu Jan 25 15:56:28 EST 2018


On Thu, Jan 25, 2018 at 1:49 PM, Marten van Kerkwijk <
m.h.vankerkwijk at gmail.com> wrote:

> On Thu, Jan 25, 2018 at 1:16 PM, Stefan van der Walt
> <stefanv at berkeley.edu> wrote:
> > On Mon, 22 Jan 2018 10:11:08 -0500, Marten van Kerkwijk wrote:
> >>
> >> I think on the consistency argument is perhaps the most important:
> >> views are very powerful and in many ways one *counts* on them
> >> happening, especially in working with large arrays.
> >
> >
> > I had the same gut feeling, but the fancy indexing example made me
> > pause:
> >
> > In [9]: x = np.arange(12, dtype=float).reshape((3, 4))
> >
> > In [10]: p = x[[0, 1]]  # copy of data
> >
> > Then:
> >
> > In [11]: x = np.array([(0, 1), (2, 3)], dtype=[('a', int), ('b', int)])
> >
> > In [12]: p = x[['a', 'b']]  # copy of data, but proposal will change that
>

What does this do?
p = x[['a', 'b']].copy()


My impression is that the problems with the view are because the padded
view doesn't behave like a "standard" dtype or array, i.e. the follow-up
behavior is the problematic part.

Josef



> >
> > We're not doing the same kind of indexing here exactly (in one case we
> > grab elements, in the other parts of elements), but the view behavior
> > may still break the "mental expectation".
>
> A bit off-topic, but maybe this is another argument to just allow
> `x['a', 'b']` -- I never understood why a tuple was not the
> appropriate iterable for getting multiple items from a record.
>
> -- Marten
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20180125/183423dc/attachment.html>


More information about the NumPy-Discussion mailing list