python中求二维列表的最大最小值,二维数组python上的最小值

更新时间:2023-07-18 05:39:36 阅读: 评论:0

python中求⼆维列表的最⼤最⼩值,⼆维数组python上的最⼩爱鸟
河北医药诚信网
I have an array of the following structure which is simplified for this question:
贾善银8 2 3 4 5 6
3 6 6 7 2 6
3 8 5 1 2 9
6 4 2
7
如何查询银行卡余额8 3
I wish to find the minimum value in this 2D array however using the inbuilt min function returns a value error:
ValueError: The truth value of an array with more than one element is ambiguous. U a.any() or a.all()
吉他的英文
I have looked into the alternative of using np.argmin:qq红包
However it only evaluates along a single axis and returns the index of the minimum value along a single row/column whereas I wish to evaluate the whole array and return the lowest value not the indices.
If it is possible to return the index values of the lowest item in the array then that would be preferable also as from that the lowest value can easily be found.
EDIT: Thanks to the comments below np.min is the solution I was looking for and I was not aware of it existing so my answer is solved.
解决⽅案However it only evaluates along a single axis and returns the index of the minimum value along a single row/column whereas I wish to evaluate the whole array and return the lowest value not the indices.
numpy.argmin does not by default evaluate along a single axis, the default is to evaluate along the flattened matrix and it returns the linear index in the flattened array; from the numpy docs that you linked:
By default, the index is into the flattened array, otherwi along the specified axis.
Either way, u numpy.amin or numpy.min to return the minimum value, or equivalently for an array arrname u
arrname.min(). As you mentioned, numpy.argmin returns the index of the minimum value (of cour, you can then u this index to return the minimum value by indexing your array with it). You could also flatten into a single dimension array with arrname.flatten() and pass that into the built-in min function.
The four following methods produce what you want.
import numpy as np
values = np.array([
专业调查报告[8,2,3,4,5,6],
[3,6,6,7,2,6],
[3,8,5,1,2,9],
[6,4,2,7,8,3]])
幼儿社会领域教案values.min() # = 1
np.min(values) # = 1
np.amin(values) # = 1
min(values.flatten()) # = 1

本文发布于:2023-07-18 05:39:36,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/1102545.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:领域   列表   河北   查询   调查报告   社会   教案
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图