Vocabulary Book. Reprinting a lot because it is troublesome to search every time. There is an original URL.
take (indices, axis =)
methodʻIndices can be an array. However, it is not possible to specify multiple dimensions by putting tuples in ʻaxis
.
nx, ny, nz = 2, 3, 4
arr = np.arange(nx * ny * nz).reshape(nx, ny, nz)
arr.take(0, axis=0) # arr[0]Same as
arr.take(1, axis=1) # arr[:,1]Same as
[Numpy: numpy.take] (https://docs.scipy.org/doc/numpy/reference/generated/numpy.take.html)
slice (None)
or slice (None, None, None)
is the same as :
in the index.
#The following is arr[:,0,2]Same as
I = [slice(None)] * arr.ndim # [:,:,:]Same as
I[1] = 0
I[2] = 2
arr[tuple(I)]
[stackoverflow: Dynamic axis indexing of Numpy ndarray] (https://stackoverflow.com/questions/31094641/dynamic-axis-indexing-of-numpy-ndarray)
Recommended Posts