"""
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程序,希望对大家有帮助
python中取得矩阵中最大元素的位置
最新推荐文章于 2025-05-12 12:55:08 发布
本文介绍了一个简单的Python程序,用于找出给定矩阵中的最大值及其所在的位置(行和列)。通过使用NumPy库,该程序实现了高效查找,并展示了如何获取矩阵的维度。

368

被折叠的 条评论
为什么被折叠?



