In NumPy, we can find maximum, minimum elements in a Ndarray and also sum of Ndarray by using following function.
ndarray.max():
This function of ndarray.numpy returns the maximum value of ndarray object.
Syntax:
numpy.max(input_array)
Example:
# import numpy library
import numpy as np
# create numpy array
a = np.array([10,20,30,40,50])
# find the maximum element in the array
b = np.max(a)
print(b)
Output: 50
ndarray.min():
This function of ndarray.numpy returns the minimum value of ndarray object.
Syntax:
numpy.min(input_array)
Example:
# import numpy library
import numpy as np
# create numpy array
a=np.array([10,20,30,40,50])
# find the minimum element in the array
b=np.min(a)
print(b)
Output: 10
numpy.sum():
This function is used to return the sum of all elements of an array over specified axis. It is possible to add rows and column elements of an array.
Syntax:
numpy.sum(array, axis=None, dtype=None, out=None, keepdims=<no value>, initial=<no value>)
Parameters:
- array: It is the array whose elements are used as the source for sum.
- axis: It describe the axis along which a sum is performed.
- dtype: It is used to specify the type of return array.
- out: It is used to specify the array to place the result.
- keepdims: It defines the boolean value.If the parameter is set to True, the axis which are reduced are left t in the result as dimensions with size one.
- initial: It specifies the starting value of sum.
Example:
import numpy as np
a=np.array([1,2,3,4,5])
b=np.sum(a)
print(b)
Output: 15
- Log in to post comments