YouTip LogoYouTip

Numpy Mathematical Functions

NumPy contains a large number of various mathematical operations, including trigonometric functions, arithmetic operations, complex number processing functions, etc.\\n\\n### Trigonometric Functions\\n\\nNumPy provides standard trigonometric functions: sin(), cos(), tan().\\n\\n## Example\\n\\n```python\\nimport numpy as np\\na = np.array([0,30,45,60,90])\\nprint('Sine values of different angles:')\\nprint(np.sin(a*np.pi/180))\\nprint('n')\\nprint('Cosine values of angles in the array:')\\nprint(np.cos(a*np.pi/180))\\nprint('n')\\nprint('Tangent values of angles in the array:')\\nprint(np.tan(a*np.pi/180))\\n\\nOutput:\\n\\nSine values of different angles:\\n[0. 0.5 0.70710678 0.8660254 1. ]\\nCosine values of angles in the array:\\n[ 1.00000000e+00 8.66025404e-01 7.07106781e-01 5.00000000e-01\\n 6.12323400e-17]\\nTangent values of angles in the array:\\n[ 0.00000000e+00 5.77350269e-01 1.00000000e+00 1.73205081e+00\\n 1.63312394e+16]\\n\\nThe arcsin, arccos, and arctan functions return the inverse trigonometric functions of sin, cos, and tan for the given angles.\\n\\nThe results of these functions can be converted from radians to degrees using the numpy.degrees() function.\\n\\n## Example\\n\\n```python\\nimport numpy as np\\na = np.array([0,30,45,60,90])\\nprint('Array containing sine values:')\\nsin = np.sin(a*np.pi/180)\\nprint(sin)\\nprint('n')\\nprint('Calculate the inverse sine of the angle, returning the value in radians:')\\ninv = np.arcsin(sin)\\nprint(inv)\\nprint('n')\\nprint('Verify the result by converting to degrees:')\\nprint(np.degrees(inv))\\nprint('n')\\nprint('arccos and arctan Function behavior is similar:')\\ncos = np.cos(a*np.pi/180)\\nprint(cos)\\nprint('n')\\nprint('Inverse Cosine:')\\ninv = np.arccos(cos)\\nprint(inv)\\nprint('n')\\nprint('Degree units:')\\nprint(np.degrees(inv))\\nprint('n')\\nprint('tan Function:')\\ntan = np.tan(a*np.pi/180)\\nprint(tan)\\nprint('n')\\nprint('Inverse Tangent:')\\ninv = np.arctan(tan)\\nprint(inv)\\nprint('n')\\nprint('Degree units:')\\nprint(np.degrees(inv))\\n\\nOutput:\\n\\nArray containing sine values:\\n[0. 0.5 0.70710678 0.8660254 1. ]\\nCalculate the inverse sine of the angle, returning the value in radians:\\n[0. 0.52359878 0.78539816 1.04719755 1.57079633]\\nVerify the result by converting to degrees:\\n[ 0. 30. 45. 60. 90.]\\n arccos and arctan Function behavior is similar:\\n[ 1.00000000e+00 8.66025404e-01 7.07106781e-01 5.00000000e-01\\n 6.12323400e-17]\\nInverse Cosine:\\n[0. 0.52359878 0.78539816 1.04719755 1.57079633]\\nDegree units:\\n[ 0. 30. 45. 60. 90.]\\n tan Function:\\n[ 0.00000000e+00 5.77350269e-01 1.00000000e+00 1.73205081e+00\\n 1.63312394e+16]\\nInverse Tangent:\\n[0. 0.52359878 0.78539816 1.04719755 1.57079633]\\nDegree units:\\n[ 0. 30. 45. 60. 90.]\\n\\n### Rounding Functions\\n\\nnumpy.around() function returns the rounded value of the specified number.\\n\\nnumpy.around(a,decimals)\\n\\nParameter description:\\n\\n* a: array\\n* decimals: Number of decimal places to round. Default is 0. If negative, integers will be rounded to the left of the decimal point\\n\\n## Example\\n\\n```python\\nimport numpy as np\\na = np.array([1.0,5.55, 123, 0.567, 25.532])\\nprint('Original array:')\\nprint(a)\\nprint('n')\\nprint('After rounding:')\\nprint(np.around(a))\\nprint(np.around(a, decimals = 1))\\nprint(np.around(a, decimals = -1))\\n\\nOutput:\\n\\nOriginal array:\\n[ 1. 5.55 123. 0.567 25.532]\\nAfter rounding:\\n[ 1. 6. 123. 1. 26.]\\n[ 1. 5.6 123. 0.6 25.5]\\n[ 0. 10. 120. 0. 30.]\\n\\n### numpy.floor()\\n\\nnumpy.floor() returns the largest integer less than or equal to the
← Numpy Byte SwappingNumpy Terating Over Array β†’