Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.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 3.x 从具有条件的数组中获取索引值_Python 3.x - Fatal编程技术网

Python 3.x 从具有条件的数组中获取索引值

Python 3.x 从具有条件的数组中获取索引值,python-3.x,Python 3.x,我有一个这样的np数组 a = [ [0. 0. 1. 0.] [0. 1. 0. 0.] [1. 0. 0. 0.] [0. 0. 1. 0.] [0. 0. 1. 0.] ] 如果项目值为==1,我想获取第三列中的所有行索引 a[:,2:2+1]==1 那样的话,我的结果是 索引=[0 3,3] 有什么功能我可以使用吗 import numpy as np a=np.array([[0, 0, 1, 0],[0, 1, 0, 0],[1,0, 0, 0],[0, 0, 1

我有一个这样的np数组

a = [ [0. 0. 1. 0.]
  [0. 1. 0. 0.]
  [1. 0. 0. 0.]
  [0. 0. 1. 0.]
  [0. 0. 1. 0.]
]
如果项目值为==1,我想获取第三列中的所有行索引

a[:,2:2+1]==1
那样的话,我的结果是 索引=[0 3,3] 有什么功能我可以使用吗

import numpy as np
a=np.array([[0, 0, 1, 0],[0, 1, 0, 0],[1,0, 0, 0],[0, 0, 1, 0]])
index,value_first_at_index=np.where(a[:,2:3]==1)
print(index)

没有任何功能。您需要编写循环/列表理解。