0

According to the numpy doc

The definition of advanced indexing means that x[(1,2,3),] is fundamentally different than x[(1,2,3)]. The latter is equivalent to x[1,2,3] which will trigger basic selection while the former will trigger advanced indexing. Be sure to understand why this occurs.

and

Advanced indexing is triggered when the selection object, obj, is a non-tuple sequence object, an ndarray (of data type integer or bool), or a tuple with at least one sequence object or ndarray (of data type integer or bool). There are two types of advanced indexing: integer and Boolean.


However in my own testing it appears that even for tupples, if it doesn't have at least one slice object, or one np.newaxis, or one Ellipse object, then it will be triggering advanced indexing

import numpy as np

arr = np.zeros(shape=(5,5,5))
arr[(1,2,3)].flags.owndata       # evaluates to True


Is this the correct behavior?

Shawn Li
  • 419
  • 3
  • 17

1 Answers1

0
In [5]: arr = np.zeros(shape=(5,5,5))

This is basic indexing with a tuple of indices:

In [6]: arr[(1,2,3)]
Out[6]: 0.0
In [7]: type(_)
Out[7]: numpy.float64

The result is an item, not an array (or view of an array). It's the same thing as:

In [8]: arr[1,2,3]
Out[8]: 0.0
In [9]: type(_)
Out[9]: numpy.float64

Scalar numpy items like this always have their own data. I elaborate on this in my answer to a recent question about is:

https://stackoverflow.com/a/54485031/901925

hpaulj
  • 221,503
  • 14
  • 230
  • 353