Given a numpy ndarray
and an index:
a = np.random.randint(0,4,(2,3,4))
idx = (1,1,1)
is there a clean way of retrieving the 0D subarray of a
at idx
?
Something equivalent to
a[idx + (None,)].squeeze()
but less hackish?
Note that @filippo's clever
a[idx][...]
is not equivalent. First, it doesn't work for object arrays. But more seriously it does not return a subarray but a new array:
b = a[idx][...]
b[()] = 7
a[idx] == 7
# False