NumPy is a popular Python library used for scientific computing. It provides a powerful array object and a large collection of mathematical functions to operate on these arrays. One of the most useful features of NumPy is its universal functions (ufuncs) which are functions that operate element-wise on arrays. In this article, we will focus on NumPy ufunc Trigonometric.
Trigonometric functions are mathematical functions that relate to the angles and sides of a right-angled triangle. NumPy provides a set of trigonometric ufuncs that can be used to perform various trigonometric operations on arrays. These ufuncs include:
Let's take a look at some code examples to see how these ufuncs work:
The sin(x) function returns the sine of each element in the input array. Here's an example:
<p>import numpy as np</p>
<p>x = np.array([0, np.pi/2, np.pi])</p>
<p>y = np.sin(x)</p>
<p>print(y)</p>
The output of this code will be:
[0. 1. 0. ]
This means that the sine of 0 is 0, the sine of pi/2 is 1, and the sine of pi is 0.
The cos(x) function returns the cosine of each element in the input array. Here's an example:
<p>import numpy as np</p>
<p>x = np.array([0, np.pi/2, np.pi])</p>
<p>y = np.cos(x)</p>
<p>print(y)</p>
The output of this code will be:
[ 1.000000e+00 6.123234e-17 -1.000000e+00]
This means that the cosine of 0 is 1, the cosine of pi/2 is approximately 0, and the cosine of pi is -1.
The tan(x) function returns the tangent of each element in the input array. Here's an example:
<p>import numpy as np</p>
<p>x = np.array([0, np.pi/4, np.pi/2])</p>
<p>y = np.tan(x)</p>
<p>print(y)</p>
The output of this code will be:
[0.00000000e+00 1.00000000e+00 1.63312394e+16]
This means that the tangent of 0 is 0, the tangent of pi/4 is 1, and the tangent of pi/2 is a very large number.
The arcsin(x) function returns the inverse sine of each element in the input array. Here's an example:
<p>import numpy as np</p>
<p>x = np.array([0, 1, -1])</p>
<p>y = np.arcsin(x)</p>
<p>print(y)</p>
The output of this code will be:
[ 0. 1.57079633 -1.57079633]
This means that the inverse sine of 0 is 0, the inverse sine of 1 is pi/2, and the inverse sine of -1 is -pi/2.
The arccos(x) function returns the inverse cosine of each element in the input array. Here's an example:
<p>import numpy as np</p>
<p>x = np.array([0, 1, -1])</p>
<p>y = np.arccos(x)</p>
<p>print(y)</p>
The output of this code will be:
[1.57079633 0. 3.14159265]
This means that the inverse cosine of 0 is pi/2, the inverse cosine of 1 is 0, and the inverse cosine of -1 is pi.
The arctan(x) function returns the inverse tangent of each element in the input array. Here's an example:
<p>import numpy as np</p>
<p>x = np.array([0, 1, -1])</p>
<p>y = np.arctan(x)</p>
<p>print(y)</p>
The output of this code will be:
[ 0. 0.78539816 -0.78539816]
This means that the inverse tangent of 0 is 0, the inverse tangent of 1 is pi/4, and the inverse tangent of -1 is -pi/4.
These are just a few examples of the many trigonometric ufuncs available in NumPy. They can be very useful for performing complex mathematical operations on arrays.
NumPy ufunc Trigonometric provides a set of trigonometric functions that can be used to perform various trigonometric operations on arrays. These ufuncs include sin(x), cos(x), tan(x), arcsin(x), arccos(x), and arctan(x). They can be very useful for performing complex mathematical operations on arrays.
https://numpy.org/doc/stable/reference/ufuncs.html#available-ufuncs