- 教程
- 介绍
- 环境
- Ndarray 对象(Ndarray Object)
- 数据类型
- 数组属性(Array Attributes)
- 阵列创建例程(Array Creation Routines)
- 来自现有数据的数组(Array from Existing Data)
- 数值范围中的数组(Array From Numerical Ranges)
- 数值范围中的数组(Array From Numerical Ranges)
- 数值范围中的数组(Array From Numerical Ranges)
- 广播(Broadcasting)
- 迭代数组(Iterating Over Array)
- 数组操作(Array Manipulation)
- Binary 运算符
- 字符串函数(String Functions)
- 数学函数(Mathematical Functions)
- 算术运算(Arithmetic Operations)
- 统计函数(Statistical Functions)
- 统计函数(Statistical Functions)
- 字节交换(Byte Swapping)
- 副本和视图(Copies & Views)
- 矩阵库(Matrix Library)
- 线性代数(Linear Algebra)
- Matplotlib(Matplotlib)
- 使用Matplotlib的直方图(Histogram Using Matplotlib)
- I/O with NumPy
- 有用的资源
- reshape
- flat
- flatten
- ravel
- transpose
- ndarray.T
- rollaxis
- swapaxes
- broadcast
- broadcast_to
- expand_dims
- squeeze
- concatenate
- stack
- hstack
- vstack
- split
- hsplit
- vsplit
- resize
- append
- insert
- delete
- unique
- bitwise_and
- bitwise_or
- invert
- left_shift
- right_shift
- add()
- multiply()
- center()
- capitalize()
- title()
- lower()
- upper()
- split()
- splitlines()
- strip()
- join()
- replace()
- decode()
- encode()
- dot
- vdot
- inner
- matmul
- determinant
- solve
- inv
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
数学函数(Mathematical Functions)
可以理解的是,NumPy包含大量的各种数学运算。 NumPy提供标准的三角函数,算术运算函数,复数等处理。
三角函数 (Trigonometric Functions)
NumPy具有标准的三角函数,它以弧度为单位返回给定角度的三角比。
Example
import numpy as np
a = np.array([0,30,45,60,90])
print 'Sine of different angles:'
# Convert to radians by multiplying with pi/180
print np.sin(a*np.pi/180)
print '\n'
print 'Cosine values for angles in array:'
print np.cos(a*np.pi/180)
print '\n'
print 'Tangent values for given angles:'
print np.tan(a*np.pi/180)
这是它的输出 -
Sine of different angles:
[ 0. 0.5 0.70710678 0.8660254 1. ]
Cosine values for angles in array:
[ 1.00000000e+00 8.66025404e-01 7.07106781e-01 5.00000000e-01
6.12323400e-17]
Tangent values for given angles:
[ 0.00000000e+00 5.77350269e-01 1.00000000e+00 1.73205081e+00
1.63312394e+16]
arcsin, arcos,和arctan函数返回给定角度的sin,cos和tan的三角逆。 通过将弧度转换为度数, numpy.degrees() function可以验证这些函数的结果。
Example
import numpy as np
a = np.array([0,30,45,60,90])
print 'Array containing sine values:'
sin = np.sin(a*np.pi/180)
print sin
print '\n'
print 'Compute sine inverse of angles. Returned values are in radians.'
inv = np.arcsin(sin)
print inv
print '\n'
print 'Check result by converting to degrees:'
print np.degrees(inv)
print '\n'
print 'arccos and arctan functions behave similarly:'
cos = np.cos(a*np.pi/180)
print cos
print '\n'
print 'Inverse of cos:'
inv = np.arccos(cos)
print inv
print '\n'
print 'In degrees:'
print np.degrees(inv)
print '\n'
print 'Tan function:'
tan = np.tan(a*np.pi/180)
print tan
print '\n'
print 'Inverse of tan:'
inv = np.arctan(tan)
print inv
print '\n'
print 'In degrees:'
print np.degrees(inv)
其输出如下 -
Array containing sine values:
[ 0. 0.5 0.70710678 0.8660254 1. ]
Compute sine inverse of angles. Returned values are in radians.
[ 0. 0.52359878 0.78539816 1.04719755 1.57079633]
Check result by converting to degrees:
[ 0. 30. 45. 60. 90.]
arccos and arctan functions behave similarly:
[ 1.00000000e+00 8.66025404e-01 7.07106781e-01 5.00000000e-01
6.12323400e-17]
Inverse of cos:
[ 0. 0.52359878 0.78539816 1.04719755 1.57079633]
In degrees:
[ 0. 30. 45. 60. 90.]
Tan function:
[ 0.00000000e+00 5.77350269e-01 1.00000000e+00 1.73205081e+00
1.63312394e+16]
Inverse of tan:
[ 0. 0.52359878 0.78539816 1.04719755 1.57079633]
In degrees:
[ 0. 30. 45. 60. 90.]
舍入功能
numpy.around()
这是一个函数,它返回舍入到所需精度的值。 该函数采用以下参数。
numpy.around(a,decimals)
Where,
Sr.No. | 参数和描述 |
---|---|
1 | a 输入数据 |
2 | decimals 要舍入的小数位数。 默认值为0.如果为负,则将整数舍入到小数点左侧的位置 |
Example
import numpy as np
a = np.array([1.0,5.55, 123, 0.567, 25.532])
print 'Original array:'
print a
print '\n'
print 'After rounding:'
print np.around(a)
print np.around(a, decimals = 1)
print np.around(a, decimals = -1)
它产生以下输出 -
Original array:
[ 1. 5.55 123. 0.567 25.532]
After rounding:
[ 1. 6. 123. 1. 26. ]
[ 1. 5.6 123. 0.6 25.5]
[ 0. 10. 120. 0. 30. ]
numpy.floor()
此函数返回不大于输入参数的最大整数。 scalar x的最大值是最大的integer i ,因此i 《= x 。 请注意,在Python中,地板总是从0开始舍入。
Example
import numpy as np
a = np.array([-1.7, 1.5, -0.2, 0.6, 10])
print 'The given array:'
print a
print '\n'
print 'The modified array:'
print np.floor(a)
它产生以下输出 -
The given array:
[ -1.7 1.5 -0.2 0.6 10. ]
The modified array:
[ -2. 1. -1. 0. 10.]
numpy.ceil()
ceil()函数返回输入值的上限,即scalar x的ceil是最小的integer i ,使得i 》= x.
Example
import numpy as np
a = np.array([-1.7, 1.5, -0.2, 0.6, 10])
print 'The given array:'
print a
print '\n'
print 'The modified array:'
print np.ceil(a)
它将产生以下输出 -
The given array:
[ -1.7 1.5 -0.2 0.6 10. ]
The modified array:
[ -1. 2. -0. 1. 10.]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论