如何找到一个numpy的矩阵中的最小值? [英] How to find the minimum value in a numpy matrix?
本文介绍了如何找到一个numpy的矩阵中的最小值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿,这是一个快速和简单的问题...
我如何才能找到这个矩阵的最小值,但不包括0?
正如在8
ARR = numpy.array([0,56,20,44]
[68,0,56,8]
[32,56,0,44]
[68,20,56,0。]])
解决方案
随着你使用 numpy的
,您可以使用
改编[ARR大于0] .min()
为您发布的情况。
但如果你的阵列可以有负值,那么你应该使用
改编[ARR!= 0] .min()
Hey this is a quick and easy question... How would i find the minimum value of this matrix, excluding 0? As in, 8
arr = numpy.array([[ 0., 56., 20., 44.],
[ 68., 0., 56., 8.],
[ 32., 56., 0., 44.],
[ 68., 20., 56., 0.]])
解决方案
As you're using numpy
, you could use
arr[arr>0].min()
for the case you posted. but if your array could have negative values, then you should use
arr[arr != 0].min()
这篇关于如何找到一个numpy的矩阵中的最小值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文