Code前端首页关于Code前端联系我们

NumPy 教程:数学算术(三角、算术运算、处理复数等) 函数

terry 2年前 (2023-09-25) 阅读数 50 #后端开发

NumPy - 算术函数

很容易理解,NumPy 包含大量数学函数。 NumPy 支持标准三角函数、算术运算、复数处理函数等。提供。

三角函数

NumPy 具有标准三角函数,可返回给定角度(以弧度为单位)的三角比率。示例 tan 对于给定角度,函数 返回 sincostan 的反三角函数。可以通过使用函数 numpy. Degrees() 将弧度转换为角度来检查这些函数的结果。

示例

import numpy as np
a = np.array([0,30,45,60,90])  
print  '含有正弦值的数组:'
sin = np.sin(a*np.pi/180)  
print sin
print  '\n'  
print  '计算角度的反正弦,返回值以弧度为单位:'
inv = np.arcsin(sin)  
print inv
print  '\n'  
print  '通过转化为角度制来检查结果:'  
print np.degrees(inv)  
print  '\n'  
print  'arccos 和 arctan 函数行为类似:'
cos = np.cos(a*np.pi/180)  
print cos
print  '\n'  
print  '反余弦:'
inv = np.arccos(cos)  
print inv
print  '\n'  
print  '角度制单位:'  
print np.degrees(inv)  
print  '\n'  
print  'tan 函数:'
tan = np.tan(a*np.pi/180)  
print tan
print  '\n'  
print  '反正切:'
inv = np.arctan(tan)  
print inv
print  '\n'  
print  '角度制单位:'  
print np.degrees(inv)
Python

输出为:

含有正弦值的数组:
[ 0.          0.5         0.70710678  0.8660254   1.        ]

计算角度的反正弦,返回值以弧度制为单位:
[ 0.          0.52359878  0.78539816  1.04719755  1.57079633]

通过转化为角度制来检查结果:
[  0.  30.  45.  60.  90.]

arccos 和 arctan 函数行为类似:
[  1.00000000e+00   8.66025404e-01   7.07106781e-01   5.00000000e-01          
   6.12323400e-17]

反余弦:
[ 0.          0.52359878  0.78539816  1.04719755  1.57079633]

角度制单位:
[  0.  30.  45.  60.  90.]

tan 函数:
[  0.00000000e+00   5.77350269e-01   1.00000000e+00   1.73205081e+00          
   1.63312394e+16]

反正切:
[ 0.          0.52359878  0.78539816  1.04719755  1.57079633]

角度制单位:
[  0.  30.  45.  60.  90.]

将函数

numpy.around() 舍入为您需要的精确值。该函数接受以下参数。
numpy.around(a,decimals)
Python

其中:

序列号参数及说明
1.a

a

。小数 小数点后的位数。默认值为 0。如果为负数,则整数四舍五入到小数点左侧。大于输入参数。即标量x的下限是最大的i,因此i

版权声明

本文仅代表作者观点,不代表Code前端网立场。
本文系作者Code前端网发表,如需转载,请注明页面地址。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门