本文概述
Numpy包含大量数学函数, 可用于执行各种数学运算。数学函数包括三角函数, 算术函数和用于处理复数的函数。让我们讨论一下数学函数。
三角函数
Numpy包含三角函数, 用于计算弧度中不同角度的正弦, 余弦和正切。
sin, cos和tan函数返回指定角度的三角比。考虑以下示例。
例子
import numpy as np
arr = np.array([0, 30, 60, 90, 120, 150, 180])
print("\nThe sin value of the angles", end = " ")
print(np.sin(arr * np.pi/180))
print("\nThe cosine value of the angles", end = " ")
print(np.cos(arr * np.pi/180))
print("\nThe tangent value of the angles", end = " ")
print(np.tan(arr * np.pi/180))
输出
The sin value of the angles
[0.00000000e+00 5.00000000e-01 8.66025404e-01 1.00000000e+00
8.66025404e-01 5.00000000e-01 1.22464680e-16]
The cosine value of the angles
[ 1.00000000e+00 8.66025404e-01 5.00000000e-01 6.12323400e-17
-5.00000000e-