Finding angles from sine, cosine, or tangent values involves using inverse functions like arcsin, arccos, and arctan. NumPy provides the ufuncs arcsin(), arccos(), and arctan() to return angle values in radians for the given sine, cosine, or tangent values.
Determine the angle corresponding to 1.0.
import numpy as np x = np.arcsin(1.0) print(x) |
Calculate the angle for all sine values in the array.
import numpy as np arr = np.array([1, –1, 0.1]) x = np.arcsin(arr) print(x) |
Finding the hypotenuse using the Pythagorean theorem in NumPy can be done with the hypot()
function, which takes the base and height values to calculate the hypotenuse.
Calculate the hypotenuse for a base of 4 and a perpendicular of 3.
import numpy as np base = 3 perp = 4 x = np.hypot(base, perp) print(x) |