Infinity¶
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 [3]:
np.array([np.inf, np.NINF])
Out[3]:
array([ inf, -inf])
In [4]:
np.array([-1, 1]) / 0
/tmp/ipykernel_18948/1273093014.py:1: RuntimeWarning: divide by zero encountered in divide np.array([-1, 1]) / 0
Out[4]:
array([-inf, inf])
In [5]:
np.inf + np.inf
Out[5]:
inf
In [6]:
np.inf * 32
Out[6]:
inf
In [7]:
np.inf - np.inf
Out[7]:
nan
In [8]:
np.inf / np.inf
Out[8]:
nan
In [9]:
np.inf == np.inf
Out[9]:
True
In [10]:
np.NINF == np.NINF
Out[10]:
True
In [11]:
foo = np.array([4, np.inf, 1, np.NINF])
In [12]:
foo == np.inf
Out[12]:
array([False, True, False, False])
In [13]:
foo == np.NINF
Out[13]:
array([False, False, False, True])
In [14]:
np.isposinf(foo)
Out[14]:
array([False, True, False, False])
In [15]:
np.isneginf(foo)
Out[15]:
array([False, False, False, True])
In [16]:
np.isinf(foo)
Out[16]:
array([False, True, False, True])