![]() |
VOOZH | about |
NumPy contains a large number of various mathematical operations. NumPy provides standard trigonometric functions, functions for arithmetic operations, handling complex numbers, etc.
NumPy provides functions like sin(), cos() and tan() to compute trigonometric ratios element-wise for angles in radians.
| FUNCTION | DESCRIPTION |
|---|---|
Computes sine element-wise | |
Computes cosine element-wise | |
| tan() | Compute tangent element-wise. |
| arcsin() | Inverse sine, element-wise. |
| arccos() | Trigonometric inverse cosine, element-wise. |
| arctan() | Trigonometric inverse tangent, element-wise. |
| arctan2() | Element-wise arc tangent of x1/x2 choosing the quadrant correctly. |
| degrees() | Convert angles from radians to degrees. |
| rad2deg() | Convert angles from radians to degrees. |
| deg2rad | Convert angles from degrees to radians. |
| radians() | Convert angles from degrees to radians. |
| hypot() | Given the βlegsβ of a right triangle, return its hypotenuse. |
| unwrap() | Unwrap by changing deltas between values to 2*pi complement. |
The sine function returns the y-coordinate of a point on the unit circle for a given angle (in radians).
Sine values: [0.00000000e+00 1.00000000e+00 8.66025404e-01 1.22464680e-16]
Explanation:
The cosine function returns the x-coordinate of a point on the unit circle for a given angle (in radians).
Cosine values: [ 1.000000e+00 6.123234e-17 5.000000e-01 -1.000000e+00]
Explanation: np.cos(arr): computes cosine values element-wise for all angles.
Used to calculate hyperbolic sine, cosine, and tangent.
| FUNCTION | DESCRIPTION |
|---|---|
Hyperbolic sine | |
Hyperbolic cosine | |
| tanh() | Compute hyperbolic tangent element-wise. |
| arcsinh() | Inverse hyperbolic sine element-wise. |
| arccosh() | Inverse hyperbolic cosine, element-wise. |
| arctanh() | Inverse hyperbolic tangent element-wise. |
The hyperbolic sine (sinh) function returns the value of the hyperbola-based analogue of the sine function, defined as (e^x-e^(-x))/2.
Hyperbolic sine values: [ 0. 2.3012989 1.24936705 11.54873936]
Explanation: np.sinh(arr) computes the hyperbolic sine for each value element-wise.
Used to round numbers to the nearest integer or specified decimals.
| FUNCTION | DESCRIPTION |
|---|---|
| rint() | Round to nearest integer towards zero. |
| fix() | Round to nearest integer towards zero. |
| floor() | Return the floor of the input, element-wise. |
| ceil() | Return the ceiling of the input, element-wise. |
| trunc() | Return the truncated value of the input, element-wise. |
np.rint() rounds each element in an array to the nearest integer, returning a new array with the rounded values.
[ 1. 3. -3. -5.]
NumPy supports exponential, logarithmic, and power operations element-wise.
| FUNCTION | DESCRIPTION |
|---|---|
e^x element-wise | |
| expm1() | Calculate exp(x) β 1 for all elements in the array. |
| exp2() | Calculate 2**p for all p in the input array. |
| log10() | Return the base 10 logarithm of the input array, element-wise. |
| log2() | Base-2 logarithm of x. |
| log1p() | Return the natural logarithm of one plus the input array, element-wise. |
| logaddexp() | Logarithm of the sum of exponentiations of the inputs. |
| logaddexp2() | Logarithm of the sum of exponentiations of the inputs in base-2. |
np.exp() function calculates e^x for each element in an array, where e is approximately equal to 2.718 is the base of natural logarithms.
[ 2.71828183 20.08553692 148.4131591 ]
The natural logarithm (np.log) computes the logarithm of each element in the array with base e. where 'e' is approximately equal to 2.718.
[0. 1.09861229 1.60943791 5.54517744]
Arithmetic functions perform basic mathematical operations in Python, such as addition, subtraction, multiplication, and division etc.
| FUNCTION | DESCRIPTION |
|---|---|
| add() | Add arguments element-wise. |
| positive() | Numerical positive, element-wise. |
| negative() | Numerical negative, element-wise. |
| multiply() | Multiply arguments element-wise. |
| power() | First array elements raised to powers from second array, element-wise. |
| subtract() | Subtract arguments, element-wise. |
| true_divide() | Returns a true division of the inputs, element-wise. |
| floor_divide() | Return the largest integer smaller or equal to the division of the inputs. |
| float_power() | First array elements raised to powers from second array, element-wise. |
| mod() | Return the element-wise remainder of division. |
| remainder() | Return element-wise remainder of division. |
| divmod() | Return element-wise quotient and remainder simultaneously. |
Returns the reciprocal (1/x) of each element in an array. | |
performs element-wise division between arrays or numbers. |
np.reciprocal() computes the reciprocal (1/x) of each element in the input array element-wise.
0.5
numpy.divide(arr1, arr2) performs element-wise division of the first array by the second array.
[1. 9. 0.5 4.2 3.83333333]
numpy.isreal() test element-wise whether it is a real number or not(not infinity or not Not a Number) and return the result as a boolean array.
Is Real : [False True] Is Real : [ True True]
numpy.conj(x) gives the complex conjugate of a number by changing the sign of its imaginary part.
Output conjugated complex number of 2+4j : (2-4j) Output conjugated complex number of 5-8j: (5+8j)
Special functions perform advanced mathematical and numerical operations, such as convolution, element-wise calculations, interpolation, and handling NaN or complex values.
| FUNCTION | DESCRIPTION |
|---|---|
| convolve() | Returns the discrete, linear convolution of two one-dimensional sequences. |
| sqrt() | Return the non-negative square-root of an array, element-wise. |
| square() | Return the element-wise square of the input. |
| absolute() | Calculate the absolute value element-wise. |
| fabs() | Compute the absolute values element-wise. |
| sign() | Returns an element-wise indication of the sign of a number. |
| interp() | One-dimensional linear interpolation. |
| maximum() | Element-wise maximum of array elements. |
| minimum() | Element-wise minimum of array elements. |
| real_if_close() | If complex input returns a real array if complex parts are close to zero. |
| nan_to_num() | Replace NaN with zero and infinity with large finite numbers. |
| heaviside() | Compute the Heaviside step function. |
cbrt() | computes the cube root of each element in an array. |
clip() | limits array values to a min and max. |
numpy.cbrt(x) function helps user to calculate cube root of x for all x being the array elements.
[ 1. 30. 4. -10.]
numpy.clip(x, a_min, a_max) this function is used to Clip (limit) the values in an array.