简体   繁体   English

多维索引

[英]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. 我想在一个指数数组中传递一个整洁的多维数组(下面的2D示例)中的值。

It appears that I can only pass in upto 2 indices without getting an error: 看来我最多只能传递2个索引而不会出现错误:

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: 我认为您是在假设列表的每个子元素都是1点,而实际上是语法:

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 使用第3维会给您一个错误,因为您只有2维的数组

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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