Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
170 views
in Technique[技术] by (71.8m points)

Python Indexing a Multidimensional Array with a one dimensional array

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...