寻找具有最高的平均行中一个numpy的阵列 [英] Finding the row with the highest average in a numpy array

查看:109
本文介绍了寻找具有最高的平均行中一个numpy的阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于以下数组:

complete_matrix = numpy.array([
    [0, 1, 2, 4],
    [1, 0, 3, 5],
    [2, 3, 0, 6],
    [4, 5, 6, 0]])

我想与最高的平均标识行,不包括对角线零。
因此,在这种情况下,我能够识别 complete_matrix [:3]。为与最高的平均行

推荐答案

您不必担心 0 S,他们不应该效果怎么样的平均值比较,因为有将presumably是各一个排。因此,你可以做这样的事情来获得行的指数最高平均:

You don't need to worry about the 0s, they shouldn't effect how the averages compare since there will presumably be one in each row. Hence, you can do something like this to get the index of the row with the highest average:

>>> import numpy as np 
>>> complete_matrix = np.array([
...     [0, 1, 2, 4],
...     [1, 0, 3, 5],
...     [2, 3, 0, 6],
...     [4, 5, 6, 0]])
>>> np.argmax(np.mean(complete_matrix, axis=1))
3


参考:

这篇关于寻找具有最高的平均行中一个numpy的阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆