2017年2月3日 星期五

[ Python 常見問題 ] numpy - How to get the index of a maximum element in a numpy array along one axis

Source From Here
Question
I have a 2 dimensional NumPy array. I know how to get the maximum values over axes:
>>> from numpy import *
>>> a = array([[1,2,3], [4,3,1]])
>>> amax(a, axis=0) // Retrieve the maximum value of each column among all rows
array([4, 3, 3])

How can I get the indices of the maximum elements? So I would like as output array([1,1,0])

How-To
Using API:numpy.argmax: Returns the indices of the maximum values along an axis.
>>> a.argmax(axis=0)
array([1, 1, 0])


沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...