Python Numpy数组按行获取行索引搜索
我是numpy新手,我正在python中使用随机林实现集群。我的问题是: 如何在数组中找到精确行的索引?比如说Python Numpy数组按行获取行索引搜索,python,arrays,numpy,random-forest,Python,Arrays,Numpy,Random Forest,我是numpy新手,我正在python中使用随机林实现集群。我的问题是: 如何在数组中找到精确行的索引?比如说 [[ 0. 5. 2.] [ 0. 0. 3.] [ 0. 0. 0.]] 我查找[0.0.3.]并得到结果1(第二行的索引) 有什么建议吗?遵循代码(不工作…) 对于索引,枚举中的元素(leaf_node.x): 对于索引\第二个\元素,枚举(叶\节点.x)中的元素\第二个\元素: 如果(index为什么不干脆这样做呢 >>> a array([[
[[ 0. 5. 2.]
[ 0. 0. 3.]
[ 0. 0. 0.]]
我查找[0.0.3.]
并得到结果1(第二行的索引)
有什么建议吗?遵循代码(不工作…)
对于索引,枚举中的元素(leaf_node.x):
对于索引\第二个\元素,枚举(叶\节点.x)中的元素\第二个\元素:
如果(index为什么不干脆这样做呢
>>> a
array([[ 0., 5., 2.],
[ 0., 0., 3.],
[ 0., 0., 0.]])
>>> b
array([ 0., 0., 3.])
>>> a==b
array([[ True, False, False],
[ True, True, True],
[ True, True, False]], dtype=bool)
>>> np.all(a==b,axis=1)
array([False, True, False], dtype=bool)
>>> np.where(np.all(a==b,axis=1))
(array([1]),)
你应该提供简短的、自包含的、正确的(可编译的)示例。更不用说“不工作”不是问题的描述。你能用通配符这样做吗?比如第一个“0.”是否允许作为“任意值”?如果我理解正确,请尝试:a[:,1:==np.array([0,3])
而不是a==b
。因此,我们所做的只是切掉第一列并进行比较,如图所示。好的-所以通配符是不可能的。非常好的澄清。Thx
>>> a
array([[ 0., 5., 2.],
[ 0., 0., 3.],
[ 0., 0., 0.]])
>>> b
array([ 0., 0., 3.])
>>> a==b
array([[ True, False, False],
[ True, True, True],
[ True, True, False]], dtype=bool)
>>> np.all(a==b,axis=1)
array([False, True, False], dtype=bool)
>>> np.where(np.all(a==b,axis=1))
(array([1]),)