您的位置:首页 > 编程语言 > Python开发

python中取得矩阵中最大元素的位置

2015-10-25 14:01 561 查看
"""
Create by 2015-10-25

@author: zhouheng

In this function you can get the position of the element
that you want in the matrix.
"""

import numpy as np

def getPositon():
a = np.mat([[2, 5, 7, 8, 9, 89], [6, 7, 5, 4, 6, 4]])

raw, column = a.shape# get the matrix of a raw and column

_positon = np.argmax(a)# get the index of max in the a
print _positon
m, n = divmod(_positon, column)
print "The raw is " ,m
print "The column is ",  n
print "The max of the a is ", a[m , n]

getPositon()
这是求的矩阵中最大元素的所在的行与列的python程序,希望对大家有帮助
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: