说明
NumPy 教程 持续更新中,提供建议、纠错、催更等加作者微信: gr99123(备注:pandas教程)和关注公众号「盖若」ID: gairuo。跟作者学习,请进入 Python学习课程。欢迎关注作者出版的书籍:《深入浅出Pandas》 和 《Python之光》。
NumPy 大量用于统计计算,这些统计计算中的复杂公式的实现离不开它的一些基础数学函数。本文介绍 NumPy 在数学计算方面的函数。
| 方法 | 说明 | 
|---|---|
| np.sin(x, /[, out, where, casting, order, …]) | 正弦 Trigonometric sine, 按元素 | 
| np.cos(x, /[, out, where, casting, order, …]) | 余弦 Cosine, 按元素 | 
| np.tan(x, /[, out, where, casting, order, …]) | 正切 tangent, 按元素 | 
| np.arcsin(x, /[, out, where, casting, order, …]) | 反正弦 Inverse sine, 按元素 | 
| np.arccos(x, /[, out, where, casting, order, …]) | 反余弦 Trigonometric inverse cosine, 按元素 | 
| np.arctan(x, /[, out, where, casting, order, …]) | 反正切 Trigonometric inverse tangent, 按元素 | 
| np.hypot(x1, x2, /[, out, where, casting, …]) | 给定直角三角形的直角边,返回斜边 | 
| np.arctan2(x1, x2, /[, out, where, casting, …]) | x1/x2元素弧正切的象限 | 
| np.degrees(x, /[, out, where, casting, order, …]) | 将角度从弧度转换为度 | 
| np.radians(x, /[, out, where, casting, order, …]) | 将角度从度转换为弧度 | 
| np.unwrap(p[, discont, axis]) | 通过将值之间的增量更改为2*pi补码来展开 | 
| np.deg2rad(x, /[, out, where, casting, order, …]) | 将角度从度转换为弧度 | 
| np.rad2deg(x, /[, out, where, casting, order, …]) | 将角度从弧度转换为度 | 
| 方法 | 说明 | 
|---|---|
| np.sinh(x, /[, out, where, casting, order, …]) | 双曲正弦, 按元素 | 
| np.cosh(x, /[, out, where, casting, order, …]) | 双曲余弦, 按元素 | 
| np.tanh(x, /[, out, where, casting, order, …]) | 计算双曲正切, 按元素 | 
| np.arcsinh(x, /[, out, where, casting, order, …]) | 反双曲正弦, 按元素 | 
| np.arccosh(x, /[, out, where, casting, order, …]) | 反双曲余弦, 按元素 | 
| np.arctanh(x, /[, out, where, casting, order, …]) | 反双曲正切, 按元素 | 
| 方法 | 说明 | 
|---|---|
| np.around(a[, decimals, out]) | 平均舍入到给定的小数位数 | 
| np.round_(a[, decimals, out]) | 将数组舍入到给定的小数位数。 | 
| np.rint(x, /[, out, where, casting, order, …]) | 将数组的元素舍入为最接近的整数 | 
| np.fix(x[, out]) | 舍入到接近零的整数 | 
| np.floor(x, /[, out, where, casting, order, …]) | 按元素返回向下取整 | 
| np.ceil(x, /[, out, where, casting, order, …]) | 按元素返回上入整数 | 
| np.trunc(x, /[, out, where, casting, order, …]) | 按元素返回输入的截断值 | 
| 方法 | 说明 | 
|---|---|
| np.prod(a[, axis, dtype, out, keepdims, …]) | 返回给定轴上数组元素的乘积 | 
| np.sum(a[, axis, dtype, out, keepdims, …]) | 给定轴上数组元素的总和 | 
| np.nanprod(a[, axis, dtype, out, keepdims]) | 返回数组元素在给定轴上的乘积,将 nan 视为 1 | 
| np.nansum(a[, axis, dtype, out, keepdims]) | 返回给定轴上数组元素的和,将 nan 视为 0 | 
| np.cumprod(a[, axis, dtype, out]) | 返回元素沿给定轴的累积积 | 
| np.cumsum(a[, axis, dtype, out]) | 返回给定轴上元素的累积和 | 
| np.nancumprod(a[, axis, dtype, out]) | 返回数组元素在给定轴上的累积积,将 nan 视为 1 | 
| np.nancumsum(a[, axis, dtype, out]) | 返回给定轴上数组元素的累计和,将 nan 视为 0 | 
| np.diff(a[, n, axis, prepend, append]) | 返回给定轴上数组元素的累计和,将 nan 视为 0 | 
| np.ediff1d(ary[, to_end, to_begin]) | 数组中连续元素之间的差异 | 
| np.gradient(f, *varargs[, axis, edge_order]) | 返回N维数组的梯度 | 
| np.cross(a, b[, axisa, axisb, axisc, axis]) | 返回两个向量(数组)的叉积 | 
| np.trapz(y[, x, dx, axis]) | 使用复合梯形法则沿给定轴积分 | 
| 方法 | 说明 | 
|---|---|
| np.exp(x, /[, out, where, casting, order, …]) | 计算输入数组中所有元素的指数 | 
| np.expm1(x, /[, out, where, casting, order, …]) | 计算数组中所有元素的 exp(x) - 1 | 
| np.exp2(x, /[, out, where, casting, order, …]) | 为输入数组中的所有p计算2**p | 
| np.log(x, /[, out, where, casting, order, …]) | 自然对数,按元素 | 
| np.log10(x, /[, out, where, casting, order, …]) | 按元素返回输入数组的以10为底的对数 | 
| np.log2(x, /[, out, where, casting, order, …]) | x的以2为底的对数 | 
| np.log1p(x, /[, out, where, casting, order, …]) | 返回1的自然对数加上输入数组,按元素 | 
| np.logaddexp(x1, x2, /[, out, where, casting, …]) | 输入的指数和的对数 | 
| np.logaddexp2(x1, x2, /[, out, where, casting, …]) | 以2为底的输入的指数和的对数 | 
| 方法 | 说明 | 
|---|---|
| np.i0(x) | 第一类0阶修正贝塞尔函数 Modified Bessel function | 
| np.sinc(x) | 返回标准化的sinc函数 | 
| 方法 | 说明 | 
|---|---|
| np.signbit(x, /[, out, where, casting, order, …]) | 用来判断一个值是否小于0, 负数为True | 
| np.copysign(x1, x2, /[, out, where, casting, …]) | 将x1的符号更改为x2的符号(按元素) | 
| np.frexp(x[, out1, out2], / [[, out, where, …]) | 把x的元素分解成尾数和二的指数(元组) | 
| np.ldexp(x1, x2, /[, out, where, casting, …]) | 返回 x1*2**x2,按元素 | 
| np.nextafter(x1, x2, /[, out, where, casting, …]) | 返回x1到x2之后的下一个浮点值(按元素) | 
| np.spacing(x, /[, out, where, casting, order, …]) | 返回x和最近相邻数字之间的距离 | 
| 方法  | 说明 |
| ------------ | ------------ |
| np.lcm(x1, x2, /[, out, where, casting, order, …]) |  |x1|  |x2| 的最小公倍数 |
| np.gcd(x1, x2, /[, out, where, casting, order, …]) | |x1| |x2|最大公约数 |
| 方法 | 说明 | 
|---|---|
| np.add(x1, x2, /[, out, where, casting, order, …]) | 按元素加 | 
| np.reciprocal(x, /[, out, where, casting, …]) | 倒数,绝对值大于1的整数,由于Python处理整数除法的方式,结果始终为零,对于整数0,结果是溢出。 | 
| np.positive(x, /[, out, where, casting, order, …]) | 相当于x.copy(),仅为支持算术的类型定义 | 
| np.negative(x, /[, out, where, casting, order, …]) | 相反数 | 
| np.multiply(x1, x2, /[, out, where, casting, …]) | 乘变元 | 
| np.divide(x1, x2, /[, out, where, casting, …]) | 返回输入的真正除法 | 
| np.power(x1, x2, /[, out, where, casting, …]) | 第一个数组元素从第二个数组提升为幂 | 
| np.subtract(x1, x2, /[, out, where, casting, …]) | 减去 | 
| np.true_divide(x1, x2, /[, out, where, …]) | 按元素返回输入的真正除法。 | 
| np.floor_divide(x1, x2, /[, out, where, …]) | 返回小于或等于输入除法的最大整数 | 
| np.float_power(x1, x2, /[, out, where, …]) | 第一个数组元素从第二个数组提升为幂,按元素排序 | 
| np.fmod(x1, x2, /[, out, where, casting, …]) | 返回除法的元素余数 | 
| np.mod(x1, x2, /[, out, where, casting, order, …]) | 返回除法的元素余数 | 
| np.modf(x[, out1, out2], / [[, out, where, …]) | 按元素返回数组的分数部分和整数部分 | 
| np.remainder(x1, x2, /[, out, where, casting, …]) | 返回除法的元素余数 | 
| np.divmod(x1, x2[, out1, out2], / [[, out, …]) | 同时返回元素的商和余数 | 
| 方法 | 说明 | 
|---|---|
| np.angle(z[, deg]) | 返回复杂参数的角度 | 
| np.real(val) | 返回复杂参数的真实部分 | 
| np.imag(val) | 返回复变元的虚部 | 
| np.conj(x, /[, out, where, casting, order, …]) | 按元素返回复共轭 | 
| np.conjugate(x, /[, out, where, casting, …]) | 按元素返回复共轭 | 
| 方法 | 说明 | 
|---|---|
| np.convolve(a, v[, mode]) | 返回两个一维序列的离散线性卷积 | 
| np.clip(a, a_min, a_max[, out]) | 剪裁(限制)数组中的值 | 
| np.sqrt(x, /[, out, where, casting, order, …]) | 按元素返回数组的非负平方根 | 
| np.cbrt(x, /[, out, where, casting, order, …]) | 按元素返回数组的立方根 | 
| np.square(x, /[, out, where, casting, order, …]) | 返回输入的元素平方 | 
| np.absolute(x, /[, out, where, casting, order, …]) | 按元素计算绝对值 | 
| np.fabs(x, /[, out, where, casting, order, …]) | 按元素计算绝对值 | 
| np.sign(x, /[, out, where, casting, order, …]) | 返回数字符号的元素指示 | 
| np.heaviside(x1, x2, /[, out, where, casting, …]) | 计算Heaviside阶跃函数 | 
| np.maximum(x1, x2, /[, out, where, casting, …]) | 数组元素的按元素最大值 | 
| np.minimum(x1, x2, /[, out, where, casting, …]) | 数组元素的元素最小值 | 
| np.fmax(x1, x2, /[, out, where, casting, …]) | 数组元素的按元素最大值 | 
| np.fmin(x1, x2, /[, out, where, casting, …]) | 数组元素的元素最小值 | 
| np.nan_to_num(x[, copy, nan, posinf, neginf]) | 将NaN替换为零,将无穷大替换为大的有限数(默认行为),或替换为用户使用NaN、posinf和/或neginf关键字定义的数字 | 
| np.real_if_close(a[, tol]) | 如果输入是复数,所有虚部都接近零,则返回实部 | 
| np.interp(x, xp, fp[, left, right, period]) | 单调递增样本点的一维线性插值 | 
更新时间:2022-06-10 09:40:09 标签:numpy 数学