So I create an array
joint = np.zeros((2,2,4,2))
and I want to access a location specified another array, initialized as:
index = np.array([0,0,0,0])
but will then become something like:
print(index)
[0 1 1 1]
so joint[index]
should access the single element at the zeroth index of the zeroth dimension, first index of the first dimension, first index of the second dimension, and first index of the third dimension. However, when I call
print(joint[index].shape)
(trying to access a single element) I am met with:
(4, 2, 4, 2)
Returning an array. I know that I can do joint[0,1,1,1]
to grab this single element, that works, but the index will be changing thousands of times within a loop. so I need to use a variable as the index. I've also tried using a list as the index, but to no avail.
question from:
https://stackoverflow.com/questions/65893703/python-indexing-a-multidimensional-array-with-a-one-dimensional-array 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…