List of Python Numpy methods with Format and Example

here you will get the Python numpy functions with the format additionally,
mostly used python numpy functions with the example and alternate example.
Also to explain it in a better way.

#importing numpy

import numpy as np
in the example, we will { np }


np.all(element)

code Example:

a =np.array([1,2,4])
print(np.all(a))

#output
>> true

a =np.array([1,2,0])
print(np.all(a))

#output
>> false

Explanation: all function returns True. if all elements of the input array evaluate as True. if the array will have 0 it will give false.


np.any(element)

code Example:

a = np.array([1,2,0])
print(np.any(a))

#output
>> true

a = np.array[0,0,0]
print(np.any(a))

#output
>> false

Explanation: any function, returns True if any element of the input array evaluate as True. if the array will have all 0, then it will give false.


np.argmax(element)

code Example:

a = np.array([1,2,0])
print(np.argmax(a))

#output
>> 1

Explanation: argmax function, returns the indices of the maximum value along an axis.


np.argmin(element)

code Example:

a = np.array([1,2,0])
print(np.argmin(a))

#output
>> 2

Explanation: argmin function, returns the indices of the minimum value along an axis.


np.argmax(element)

code Example:

a = np.array([1,2,0])
print(np.argsort(a))

#output
>> [2,0,1]

Explanation: argsort function, returns the indices that would sort an array


np.round(element)

code Example:

a = np.array([1.0093,2.0232,0.9890])
print(np.round(a,2))

#output
>> [1.01 2.02 0.99]

Explanation: round function, round off the elements of the array to the given decimal points, in this case, it is 2.


Leave a Comment