numpy 算术运算(Arithmetic operations)
numpy算数运算函数
name | descripe |
---|---|
add(x1, x2[, out]) | Add arguments element-wise. |
reciprocal(x[, out]) | Return the reciprocal of the argument, element-wise. |
negative(x[, out]) | Numerical negative, element-wise. |
multiply(x1, x2[, out]) | Multiply arguments element-wise. |
divide(x1, x2[, out]) | Divide arguments element-wise. |
power(x1, x2[, out]) | First array elements raised to powers from second array, element-wise. |
subtract(x1, x2[, out]) | Subtract arguments, element-wise. |
true_divide(x1, x2[, out]) | Returns a true division of the inputs, element-wise. |
floor_divide(x1, x2[, out]) | Return the largest integer smaller or equal to the division of the inputs. |
fmod(x1, x2[, out]) | Return the element-wise remainder of division. |
mod(x1, x2[, out]) | Return element-wise remainder of division. |
modf(x[, out1, out2]) | Return the fractional and integral parts of an array, element-wise. |
remainder(x1, x2[, out]) | Return element-wise remainder of division. |
1.numpy.add(x1, x2[, out ]) = ufunc‘add’
求和
>>> np.add(1.0, 4.0)
5.0
>>> x1 = np.arange(9.0).reshape((3, 3))
[[ 0. 1. 2.]
[ 3. 4. 5.]
[ 6. 7. 8.]]
>>> x2 = np.arange(3.0)
[ 0. 1. 2.]
>>> np.add(x1, x2)
array([[ 0., 2., 4.],
[ 3., 5., 7.],
[ 6., 8., 10.]])
2.numpy.reciprocal(x[, out ]) = ufunc ‘reciprocal’
求倒数
>>> np.reciprocal(2.)
0.5
>>> np.reciprocal([1, 2., 3.33])
array([ 1. , 0.5 , 0.3003003])
3.numpy.negative(x[, out ]) = ufunc ‘negative’
求相反数
>>> np.negative([1.,-1.])
array([-1., 1.])
4.numpy.multiply(x1, x2[, out ]) = ufunc ‘multiply’
求积
>>> np.multiply(2.0, 4.0)
8.0
>>> x1 = np.arange(9.0).reshape((3, 3))
>>> x2 = np.arange(3.0)
>>> np.multiply(x1, x2)
array([[ 0., 1., 4.],
[ 0., 4., 10.],
[ 0., 7., 16.]])
5.numpy.divide(x1, x2[, out ]) = ufunc ‘divide’
求商
>>> np.divide(2.0, 4.0)
0.5
>>> x1 = np.arange(9.0).reshape((3, 3))
>>> x2 = np.arange(3.0)
>>> np.divide(x1, x2)
array([[ NaN, 1. , 1. ],
[ Inf, 4. , 2.5],
[ Inf, 7. , 4. ]])
numpy.true_divide(x1, x2[, out ]) = ufunc ‘true_divide’
>>> x = np.arange(5)
>>> np.true_divide(x, 4)
array([ 0. , 0.25, 0.5 , 0.75, 1. ])
>>> x/4
array([0, 0, 0, 0, 1])
>>> x//4
array([0, 0, 0, 0, 1])
numpy.floor_divide(x1, x2[, out ]) = ufunc ‘floor_divide’
>>> np.floor_divide(7,3)
2
>>> np.floor_divide([1., 2., 3., 4.], 2.5)
array([ 0., 0., 1., 1.])
6.numpy.power(x1, x2[, out ]) = ufunc ‘power’
求幂
>>> x1 = range(6)
>>> x1
[0, 1, 2, 3, 4, 5]
>>> np.power(x1, 3)
array([ 0, 1, 8, 27, 64, 125])
>>> x2 = [1.0, 2.0, 3.0, 3.0, 2.0, 1.0]
>>> np.power(x1, x2)
array([ 0., 1., 8., 27., 16., 5.])
7.numpy.subtract(x1, x2[, out ]) = ufunc ‘subtract’
求差
>>> np.subtract(1.0, 4.0)
-3.0
>>> x1 = np.arange(9.0).reshape((3, 3))
>>> x2 = np.arange(3.0)
>>> np.subtract(x1, x2)
array([[ 0., 0., 0.],
[ 3., 3., 3.],
[ 6., 6., 6.]])
8.numpy.fmod(x1, x2[, out ]) = ufunc ‘fmod’
求余
>>> np.fmod([-3, -2, -1, 1, 2, 3], 2)
array([-1, 0, -1, 1, 0, 1])
>>> np.remainder([-3, -2, -1, 1, 2, 3], 2)
array([1, 0, 1, 1, 0, 1])
>>> np.fmod([5, 3], [2, 2.])
array([ 1., 1.])
>>> a = np.arange(-3, 3).reshape(3, 2)
>>> a
array([[-3, -2],
[-1, 0],
[ 1, 2]])
>>> np.fmod(a, [2,2])
array([[-1, 0],
[-1, 0],
[ 1, 0]])
numpy.mod(x1, x2[, out ]) = ufunc ‘remainder’
>>> np.remainder([4, 7], [2, 3])
array([0, 1])
>>> np.remainder(np.arange(7), 5)
array([0, 1, 2, 3, 4, 0, 1])
numpy.remainder(x1, x2[, out ]) =
>>> np.remainder([4, 7], [2, 3])
array([0, 1])
>>> np.remainder(np.arange(7), 5)
array([0, 1, 2, 3, 4, 0, 1])
9.numpy.modf(x[, out1, out2 ]) = ufunc ‘modf’
求整,求小数
>>> np.modf([0, 3.5])
(array([ 0. , 0.5]), array([ 0., 3.]))
>>> np.modf(-0.5)
(-0.5, -0)
numpy 算术运算(Arithmetic operations)相关推荐
- 【平衡规划】Arithmetic Operations(CF1654E)
正题 CF1654E luogu 正题 给你一个正整数序列,你可以让一个位置变成任意整数,问你最少修改多少个数,能使得其成为等差序列 解题思路 考虑根号分治 对于公差小于 n\sqrt{n}n 的, ...
- E. Arithmetic Operations 根号分治
题意:1e5长的数组,ai<=1e5,问要将其变成等差数列的最小次数: 分析: 简单分析可得 -- 显然这个答案是固定的,就是原数列本来就能成为等差数列的最大个数. 但是最直接的想法是 的,一维 ...
- 什么是算术运算和逻辑运算_8086微处理器的算术和逻辑运算
什么是算术运算和逻辑运算 逻辑指令 (Logical Instructions) a) AND: Logical AND a)AND:逻辑AND Atleast one of the operant ...
- python将小数转为分数_Python分数
python将小数转为分数 Python分数模块 (Python fractions module) As we know, a fraction is a number which represen ...
- Spring Boot - Thymeleaf模板简介以及集成
文章目录 Spring Boot - Thymeleaf模板简介以及集成 1.什么是Thymeleaf? 2.标准表达式 2.1 变量表达式 2.2 选择表达式/星号表达式 2.3 URL表达式 2. ...
- 《泛型编程与stl》
以下是STL六大组件(componments): adapters 配接器 用来修饰其他组件.包括iterator adapters.function adapters.container ada ...
- OpenCV_008-OpenCV 中的图像算术运算
本文主要内容来自于 OpenCV-Python 教程 的 核心操作 部分,这个部分的主要内容如下: 图像的基本操作 学习读取和编辑像素值,使用图像 ROI 和其它的基本操作. 图像的算术运算 对图像执 ...
- 先进的NumPy数据科学
We will be covering some of the advanced concepts of NumPy specifically functions and methods requir ...
- Python NumPy教程
Welcome to Python NumPy tutorial. In our previous tutorial, we learned about Python switch case. In ...
最新文章
- MySQL---Subquery returns more than 1 row
- 链表中是否存在环的问题,及环入口在链表中位置(Linked List Cycle II)
- 前端学习(2602):什么是跨域请求和跨域请求数据数据的表现
- Linux 修改用户名的主目录 家目录
- 爆点客源4.1.0活动营销应用56版 修复朋友圈不显示问题
- 微信小程序|开发实战篇之十一---商品页面和购物车页面
- IE与FF的常见兼容问题及总结
- mysql服务器的搭建_基于linux的Mysql服务器的搭建
- 修改Android Studio默认的gradle配置文件
- C/C++线程与多线程工作笔记002---C++中的LPVOID类型
- Mac无法打开CORE Keygen
- 正点原子STM32F407+AD7606+RT-Thread Studio 调试记录
- 读《人性的优点》有感
- 暑假集训后的一些感想
- android喜马拉雅播放器,喜马拉雅车载播放器(随车听)-喜马拉雅FM车机版v2.0.0 安卓版-腾牛安卓网...
- 【OpenCV】OCR文档识别
- 上职高数学不好可以学计算机吗,如何学好职高的数学
- python制作聊天软件_一步一步教你做聊天软件(Python实现+非阻塞)
- CCD与CMOS的区别?
- MSC/VLR/SSP
热门文章
- oracle库存会计期无法打开,打开调整会计期出错!(有图)
- 分别用邻接矩阵和邻接表实现图的深度优先遍历和广度优先遍历_数据结构与算法:三十张图弄懂「图的两种遍历方式」...
- C++ 泛型编程的基础--模板初识及应用
- 计算机是通过 来访问存储单元的,计算机是通过____来访问存储单元的
- 建立唯一索引后mysql策略_【MySQL】MySQL索引背后的之使用策略及优化【转】
- ipython版本_1. Python版本的选择与安装
- 天籁obd接口针脚定义_关于手机MicroUSB接口数据线,这里有最详细解说
- 建行计算机招聘考试考什么,银行招聘考试考什么
- springboot 对象 空指针_C++ this指针的理解和作用
- android中intent放数据类型,Android Intent传递数据底层分析详细介绍