NumPy Math functions

Addition of NumPy array

import numpy as np

n1 = np.array([10, 20])
n2 = np.array([30, 40])

np.sum([n1, n2])
Output = 100

We can also add only column or row using axis parameter.

np.sum([n1, n2], axis = 0)
Output: array([30, 40])

np.sum([n1, n2], axis = 1)
Output: array([30, 70])

How to calculate Mean of numPy array?

import numpy as np
n1 = np.array([10, 20, 30, 40, 50, 60])
np.mean(n1)
Output: 35

How to calculate Standard Deviation of array?

np.std(n1)

How to calculate Median function of array?

np.median(n1)

Leave a Comment

Your email address will not be published. Required fields are marked *