Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
嘿,这是一个快速而简单的问题......我如何找到这个矩阵的最小值,不包括 0?如,8
arr = numpy.array([[ 0., 56., 20., 44.], [ 68., 0., 56., 8.], [ 32., 56., 0., 44.], [ 68., 20., 56., 0.]])
当你使用numpy时,你可以使用
numpy
arr[arr>0].min()
对于您发布的案例。但如果你的数组可能有负值,那么你应该使用
arr[arr != 0].min()