Math Functions¶
In [1]:
%pip install numpy
import numpy as np
Requirement already satisfied: numpy in /home/samrat/Documents/numpy-torch-tutorials/venv/lib/python3.8/site-packages (1.24.4) Note: you may need to restart the kernel to use updated packages.
In [17]:
squee = np.random.randint(low=0, high=10, size=(3,3)).astype(float)
squee
Out[17]:
array([[4., 7., 8.], [1., 1., 9.], [6., 8., 4.]])
In [18]:
np.sum(squee)
Out[18]:
48.0
In [19]:
np.sum(squee, axis=0)
Out[19]:
array([11., 16., 21.])
In [20]:
np.sum(squee, axis=1)
Out[20]:
array([19., 11., 18.])
In [21]:
squee[0, 0] = np.nan
np.sum(squee)
Out[21]:
nan
In [22]:
np.sum(squee, where=~np.isnan(squee))
Out[22]:
44.0
In [23]:
np.sum(np.nan_to_num(squee))
Out[23]:
44.0
In [25]:
np.nansum(squee)
Out[25]:
44.0