获取值在矩阵中的位置(numpy.float64)

问题描述 投票:0回答:1

im试图找到矩阵最小值的位置。像图中一样。在那种情况下,最小值是-35,所以我需要找到位置:(2,4)。无论我是以行还是列为单位获取答案,或者以1或0开始行和列都无所谓。

我尝试使用np.where()命令,但不起作用。数据为numpy.float64类型。

enter image description here

python new-operator
1个回答
1
投票

这在np.argmin的文档中已解决,可以使用np.argmin

示例

np.unravel_index

注意,也可以使用import numpy as np x = np.random.random((5,5)) >>> x array([[0.27272346, 0.98320703, 0.60834759, 0.2069243 , 0.90370303], [0.87209273, 0.52894458, 0.68152673, 0.25921476, 0.58229599], [0.27519671, 0.13970337, 0.57864639, 0.37383134, 0.97409805], [0.48481975, 0.19691474, 0.4825715 , 0.91004626, 0.34862765], [0.51914768, 0.43313715, 0.2819287 , 0.60615095, 0.12990098]]) >>> np.unravel_index(np.argmin(x, axis=None), x.shape) (4, 4) 解决方案:

np.where
© www.soinside.com 2019 - 2024. All rights reserved.