Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.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 [0]在numpy中的作用是什么。where(y_euler<;0.0)[0]_Python_Arrays_Numpy - Fatal编程技术网

Python [0]在numpy中的作用是什么。where(y_euler<;0.0)[0]

Python [0]在numpy中的作用是什么。where(y_euler<;0.0)[0],python,arrays,numpy,Python,Arrays,Numpy,还有,这两者之间的区别是什么: idx_negative_euler = numpy.where(y_euler<0.0)[0] idx\u negative\u euler=numpy。其中(y\u euler[0]表示“获取序列的第一项”。例如,如果您有以下列表: x = [5, 7, 9] 那么x[0]将是该序列的第一项:5 numpy.where()返回一个序列。将[0]放在该表达式的末尾将获得该序列中的第一项 [0][0]的意思是“获取序列中的第一项(它本身也是一个序列),然

还有,这两者之间的区别是什么:

idx_negative_euler = numpy.where(y_euler<0.0)[0]
idx\u negative\u euler=numpy。其中(y\u euler
[0]
表示“获取序列的第一项”。例如,如果您有以下列表:

x = [5, 7, 9]
那么
x[0]
将是该序列的第一项:5

numpy.where()
返回一个序列。将
[0]
放在该表达式的末尾将获得该序列中的第一项


[0][0]
的意思是“获取序列中的第一项(它本身也是一个序列),然后获取该序列中的第一项”。因此,如果
numpy.where()
返回一个列表列表,
[0][0]
将获取第一个列表中的第一项。

制作一个简单的1d数组:

In [60]: x=np.array([0,1,-1,2,-1,0])
其中返回数组的元组
(…,)
,每个维度一个:

In [61]: np.where(x<0)
Out[61]: (array([2, 4], dtype=int32),)
x[2,4]
x[([2,4],)]
执行相同的索引


在处理2d或更高的dim数组时,
tuple
值的有用性变得更加明显。在这种情况下,
np.where(…)[0]
将给出“rows”索引数组。但是
where(…)[0]
在通常不需要元组层的1d情况下最为常见。

为什么不在不使用
[0]
的情况下尝试表达式?使用它可以从序列中获得第一个元素,因此可以推测
np.where()[0]
返回序列。
np.where()
返回数组轴上的索引元组。请检查并在页面中搜索术语
[0]
In [61]: np.where(x<0)
Out[61]: (array([2, 4], dtype=int32),)
In [62]: np.where(x<0)[0]
Out[62]: array([2, 4], dtype=int32)
In [63]: np.where(x<0)[0][0]
Out[63]: 2
In [64]: x[np.where(x<0)]
Out[64]: array([-1, -1])