简体   繁体   中英

Multiple Multi Dimensional Indexing

I want to find the values in a numpty multidimensional array (2D example below) be passing in an array of indicies.

It appears that I can only pass in upto 2 indices without getting an error:

V2 = [[1,2],[2,1]]
V3 = [[1,2],[2,1],[0,0]]
lookup = np.random.rand(3,3)
lookup[V2] #OK
lookup[V3] #IndexError: too many indices for array

The number of indexes as you use it is the number of dimensions.

I think you are making that assumption that every subelement of the list is 1 point while actually the syntax:

V2 = [[a1,a2,a3],[b1,b2,b3]]
lookup[V2]

is equivalent to accessing:

[V2[a1,b1],
V2[a2,b2],
V2[a3,b3]]

using a 3rd dimension gives you an error since you have an array with only 2 dimensions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM