Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么numpy.在哪里给我这个输出?_Python_Numpy - Fatal编程技术网

Python 为什么numpy.在哪里给我这个输出?

Python 为什么numpy.在哪里给我这个输出?,python,numpy,Python,Numpy,我正在关注numpy.where的文档页面,并找到以下代码: >>>x = np.arange(9.).reshape(3, 3) >>>x array([[ 0., 1., 2.], [ 3., 4., 5.], [ 6., 7., 8.]]) >>>np.where( x > 5 ) (array([2, 2, 2]), array([0, 1, 2])) 我不明白为什么np.where x>5给出了上面

我正在关注numpy.where的文档页面,并找到以下代码:

>>>x = np.arange(9.).reshape(3, 3)
>>>x
array([[ 0.,  1.,  2.],
   [ 3.,  4.,  5.],
   [ 6.,  7.,  8.]])
>>>np.where( x > 5 )
(array([2, 2, 2]), array([0, 1, 2])) 
我不明白为什么np.where x>5给出了上面提到的输出。如果以前有人问过这个问题,我很抱歉,但我没有发现任何相关问题。请帮忙

numpy.where返回条件为真的索引。因此,在您的示例中,x>5在以下索引中为真

  [(2,0), (2,1), (2,2)]
#  ^6.    ^7.    ^8.
如果您想从原始数组中提取这些元素,例如

>>> x[np.where( x > 5 )]
array([6., 7., 8.])