[Numpy-discussion] Multiple-field indexing: view vs copy in 1.14+
Marten van Kerkwijk
m.h.vankerkwijk at gmail.com
Thu Jan 25 13:49:18 EST 2018
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
> In : x = np.arange(12, dtype=float).reshape((3, 4))
> In : p = x[[0, 1]] # copy of data
> In : x = np.array([(0, 1), (2, 3)], dtype=[('a', int), ('b', int)])
> In : p = x[['a', 'b']] # copy of data, but proposal will change that
> 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.
More information about the NumPy-Discussion