Creating Arrays¶
In [2]:
%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(['a', 'b', 'c'])
Out[3]:
array(['a', 'b', 'c'], dtype='<U1')
In [5]:
np.array([['a','b'],['c','d'],['e','f']])
Out[5]:
array([['a', 'b'], ['c', 'd'], ['e', 'f']], dtype='<U1')
In [6]:
np.array([[
['a','b'],
['c','d'],
['e','f']],
[['g','h'],
['i','j'],
['k','l']]])
Out[6]:
array([[['a', 'b'], ['c', 'd'], ['e', 'f']], [['g', 'h'], ['i', 'j'], ['k', 'l']]], dtype='<U1')
In [9]:
np.zeros(shape=3)
Out[9]:
array([0., 0., 0.])
In [10]:
np.zeros(shape=(3,5))
Out[10]:
array([[0., 0., 0., 0., 0.], [0., 0., 0., 0., 0.], [0., 0., 0., 0., 0.]])
In [11]:
np.full(shape=(3,5), fill_value='cat')
Out[11]:
array([['cat', 'cat', 'cat', 'cat', 'cat'], ['cat', 'cat', 'cat', 'cat', 'cat'], ['cat', 'cat', 'cat', 'cat', 'cat']], dtype='<U3')
In [12]:
np.arange(start=1, stop=5, step=1)
Out[12]:
array([1, 2, 3, 4])
In [13]:
np.arange(10)
Out[13]:
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
In [14]:
np.random.randint(low=1, high=7, size=(2,3))
Out[14]:
array([[6, 3, 2], [3, 5, 4]])