python中argmin函数_Python numpy.argmin()用法及代码示例
numpy.argmin(array,axis = None,out = None):返回特定轴上数组min元素的索引。
参数:
array:Input array to work on
axis :[int, optional]Along a specified axis like 0 or 1
out :[array optional]Provides a feature to insert output to the out
array and it should be of appropriate shape and dtype
返回:
Array of indices into the array with same shape as array.shape
with the dimension along axis removed.
代码1:
# Python Program illustrating
# working of argmin()
import numpy as geek
# Working on 1D array
array = geek.arange(8)
print("INPUT ARRAY:\n", array)
# returning Indices of the min element
# as per the indices
print("\nIndices of min element:", geek.argmin(array, axis=0))
输出:
INPUT ARRAY:
[0 1 2 3 4 5 6 7]
Indices of min element: 0
代码2:
# Python Program illustarting
# working of argmin()
import numpy as geek
# Working on 2D array
array = geek.random.randint(16, size=(4, 4))
print("INPUT ARRAY:\n", array)
# returning Indices of the min element
# as per the indices
'''
[[ 8 13 5 0]
[ 0 2 5 3]
[10 7 15 15]
[ 3 11 4 12]]
^ ^ ^ ^
0 2 4 0 - element
1 1 3 0 - indices
'''
print("\nIndices of min element:", geek.argmin(array, axis = 0))
输出:
INPUT ARRAY:
[[ 8 13 5 0]
[ 0 2 5 3]
[10 7 15 15]
[ 3 11 4 12]]
Indices of min element: [1 1 3 0]
代码3:
# Python Program illustarting
# working of argmin()
import numpy as geek
# Working on 2D array
array = geek.arange(10).reshape(2, 5)
print("array:\n", array)
array[0][0] = 10
array[1][1] = 1
array[0][1] = 1
print("\narray:\n", array)
# Returns min element
print("\narray:", geek.argmin(array))
# First occurrence of an min element is given
print("\nmin ELEMENT INDICES:", geek.argmin(array, axis = 0))
输出:
array:
[[0 1 2 3 4]
[5 6 7 8 9]]
array:
[[10 1 2 3 4]
[ 5 1 7 8 9]]
array: 1
min ELEMENT INDICES: [1 0 0 0 0]
python中argmin函数_Python numpy.argmin()用法及代码示例相关推荐
- python中squeeze函数_Python numpy.squeeze()用法及代码示例
当我们要从数组形状中删除一维条目时,将使用numpy.squeeze()函数. 用法: numpy.squeeze(arr, axis=None ) 参数: arr :[数组]输入数组. axis : ...
- python not is函数_Python unittest assertIsNotNone()用法及代码示例
assertIsNotNonePython中的()是单元测试库函数,用于单元测试中以检查输入值是否为None.此函数将使用两个参数作为输入,并根据断言条件返回布尔值.如果输入值不等于无assertIs ...
- python中argmin函数_python中argmin函数_Python numpy.argmin()用法及代码示例
numpy.argmin(array,axis = None,out = None):返回特定轴上数组min元素的索引. 参数: array:Input array to work on axis : ...
- python arg_python argmin_python中argmin函数_Python numpy.argmin(
numpy.argmin(array,axis = None,out = None):返回特定轴上数组min元素的索引. 参数: array:Input array to work on axis : ...
- python中grid函数_Python / NumPy中meshgrid的目的是什么?
实际上文档中已经提到了np.mgrid的目的: np.mgrid 从坐标向量返回坐标矩阵. 在给定一维坐标数组x1,x2,...,xn的情况下,为N-D网格上的N-D标量/矢量场的矢量化评估制作N-D ...
- python中的scale_Python Matplotlib.pyplot.yscale()用法及代码示例
Matplotlib是Python中的一个库,它是NumPy库的数字-数学扩展. Pyplot是Matplotlib模块的基于状态的接口,该模块提供MATLAB-like接口. matplotlib. ...
- python的datetime举例_Python datetime.timedelta()用法及代码示例
Python timedelta()函数存在于datetime库中,该函数通常用于计算日期差,也可以用于Python中的日期操作.这是执行日期操作的最简单方法之一. 用法: datetime.time ...
- python json dumps 自定义_Python json.dumps()用法及代码示例
JSON的完整形式是JavaScript Object Notation.这意味着将使用编程语言的文本组成的脚本(可执行)文件用于存储和传输数据. Python通过名为内置的软件包支持JSONjson ...
- python中的os abort_Python os.abort()用法及代码示例
Python中的OS模块提供了与操作系统进行交互的功能.操作系统属于Python的标准实用程序模块.该模块提供了使用依赖于操作系统的功能的便携式方法. os.abort()Python中的方法用于生成 ...
最新文章
- 【2022新书】机器学习基础
- 减少资源消耗方法之一:减少状态图片
- hc05与单片机连接图_单片机科普:单片机的IO口不够用了怎么办?如何扩展单片机的IO口...
- boost的chrono模块运行计时器的测试程序
- IT行业 侃侃富士康
- yandexbot ip列表整理做俄罗斯市场的站长可以关注一下
- mysql数据库下的所有表字段
- Android studio无法创建类和接口问题解决办法。提示 Unable to parse template Class
- jQuery星级评分插件
- SAP WM Stock Removal Strategy - StringentFIFO 在仓库号级别下的先进先出
- 【POJ 2456】【二分答案】Aggressive cows(暑假 No.1)
- select函数的使用
- 【Linux基础】Linux简史
- 壮观性能服务器图片介绍,配至强7500 图解惠普ProLiant DL980 G7
- Codeforces Round #741 (Div. 2) A. The Miracle and the Sleeper
- 学 C++ ,能不能简单点?
- 惊了,近4成年薪50W+商科TOP1院校的生源都有哪些? | 北大光华2022级推免大数据
- windows C 盘扩容
- 更换Ubuntu的软件仓库为国内的镜像
- SASRec: Self-Attentive Sequential Recommendation阅读笔记
热门文章
- 69. 二叉树的层次遍历Python实现
- kaggle案例实战
- 整理好的200多java面试题,可用于机器学习
- MFC开发IM-第二篇、MFC picture 控件的用法
- linux查找出全部doc文件,linux 查找出包含某个字符串的所有文件的方法详解
- php 中文字符串截取函数--比较好的
- 华为nova 9 SE真机曝光:旗下首款一亿像素主摄 双环镜头吸睛
- 中教云教师备课云平台获北京市新技术新产品(服务)认定
- 网传“杭州市聘罗永浩为形象大使”?官方:为不实信息
- 美团工程师回应“频繁定位”:常用App权限开启时检测结果基本一致