从矩阵中获得具有最大总和值的列 [英] Get the column which have maximum sum value from matrix
本文介绍了从矩阵中获得具有最大总和值的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
让我们说:
import numpy as np
f=np.matrix("1 2; 3 4 ; 5 6")
是否可以从矩阵中检索最大列数之和的列数?怎么样?
Is retrieving number of column which have maximum sum of column from matrix possible? How?
推荐答案
您可以这样写:
>>> f.sum(axis=0).argmax()
1
因此,列1
的总和为最大值.
So column 1
sums to the greatest value.
为说明其作用:f.sum(axis=0)
对矩阵f
的列求和,返回矩阵matrix([[ 9, 12]])
.然后argmax()
用于在此求和矩阵中找到最大值的索引.
To clarify what this does: f.sum(axis=0)
sums the columns of the matrix f
, returning the matrix matrix([[ 9, 12]])
. Then argmax()
is used to find the index of the maximum value in this matrix of sums.
这篇关于从矩阵中获得具有最大总和值的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文