3.13 Mathematical functions in NumPy
Mathematical functions in NumPy: -
- We can perform arithmetic operations using various arithmetic functions such as add( ), subtract( ), multiply( ) and divide( ).
- We can also apply many other mathematical functions like sqrt( ), exp( ), abs( ) etc. on the array elements.
- The various functions that can be used on NumPy arrays are:
|
Function |
Meaning |
|
add(a, b) |
Compute addition element-wise
of two arrays |
|
subtract(a, b) |
Compute subtraction
element-wise of two arrays |
|
multiply(a, b) |
Compute multiplication
element-wise of two arrays |
|
divide(a, b) |
Returns true division of
elements element-wise |
|
power(a, b) |
Returns power value
element-wise (a raised to power b) |
|
sum(x) |
Returns sum of all elements in
the array x |
|
prod(x) |
Returns product of all elements
in the array x |
|
min(x) |
Returns smallest elements in
the array x |
|
max(x) |
Returns largest elements in the
array x |
|
sqrt(x) |
Compute square root
element-wise of array x |
|
abs(x) |
Compute absolute value
element-wise |
|
log(x) |
Compute logarithmic value
element-wise |
|
sin(x) |
Compute sine value element-wise
of array x |
|
cos(x) |
Compute cosine value
element-wise of array x |
|
tan(x) |
Compute tangent value
element-wise of array x |
|
arcsin(x) |
Compute sine inverse value
element-wise of array x |
|
arccos(x) |
Compute cosine inverse value
element-wise of array x |
|
arctan(x) |
Compute tangent inverse value
element-wise of array x |
Example1: - arithmetic functions
Output: -
Example 2: - Rounding, absolute and
trigonometric functions
Output: -
Example 3: - Statistical Functions
Output: -