Python 返回1D数组数组元组的条件搜索?

Python 返回1D数组数组元组的条件搜索?,python,numpy,Python,Numpy,我阅读了上的文档,不明白如果我检查简单1D数组的条件,为什么where会返回嵌套数组的元组 > import numpy as np > my_array = np.random.randint(1,10, (20)) > np.where(my_array > 5) (array([ 0, 1, 4, 6, 7, 8, 10, 11, 13, 15, 16, 17, 18]),) 在这种情况下,np.where为什么返回元组?为什么要嵌套结果? 我认为是为

我阅读了上的文档,不明白如果我检查简单1D数组的条件,为什么
where
会返回嵌套数组的元组

> import numpy as np
> my_array = np.random.randint(1,10, (20))
> np.where(my_array > 5)

(array([ 0,  1,  4,  6,  7,  8, 10, 11, 13, 15, 16, 17, 18]),)

在这种情况下,
np.where
为什么返回元组?为什么要嵌套结果?

我认为是为了一致性,考虑2D数组:

import numpy as np
my_array = np.random.randint(1,10, (4, 5))
pos = np.where(my_array > 5)
my_array[pos]
可以使用元组作为索引来选择位置中的所有值