我有一个500行5列的数组。我需要找到最后4列中每个列的值都大于100的所有行。我找到了一种方法来逐个检查每一列,但我希望能够同时检查所有列。我试着插入一个axis参数,但它给了我一个错误。一定有更简单的方法。这就是我可以得到的工作:
over1 = (array[:,1] >= 100)
over2 = (array[:,2] >= 100)
over3 = (array[:,3] >= 100)
over4 = (array[:,4] >= 100)
where = np.argwhere(over1&over2&over3&over4 == True)
there = array[where]
there2 = np.array(there[:,0])
#I had to reshape because the new array was a different shape for some reason
我是Python和Numpy的新手,所以遇到了一些麻烦
我相信你在寻找:
考虑一下
x
:操作
x[:, 1:] > 100
在每个元素上广播该操作,从而生成布尔矩阵。你知道吗np.all
与内置函数all
类似,如果每个元素都是True
,则它的计算结果将是False
。我们希望对每一行的每一列执行此检查,因此需要axis=1
。你知道吗遮罩现在将用于索引到原始。你知道吗
相关问题 更多 >
编程相关推荐