Concatenate¶
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 [5]:
roux = np.ones(shape=(3,2))
roux
Out[5]:
array([[1., 1.], [1., 1.], [1., 1.]])
In [6]:
gumbo = np.ones(shape=(2,2))
gumbo
Out[6]:
array([[1., 1.], [1., 1.]])
In [9]:
np.concatenate((roux, roux, roux), axis=1)
Out[9]:
array([[1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1.]])
In [10]:
np.concatenate((roux, roux, roux), axis=0)
Out[10]:
array([[1., 1.], [1., 1.], [1., 1.], [1., 1.], [1., 1.], [1., 1.], [1., 1.], [1., 1.], [1., 1.]])
In [12]:
np.concatenate((roux, gumbo), axis=0)
Out[12]:
array([[1., 1.], [1., 1.], [1., 1.], [1., 1.], [1., 1.]])
In [13]:
np.concatenate((roux, gumbo), axis=1)
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) Cell In[13], line 1 ----> 1 np.concatenate((roux, gumbo), axis=1) File <__array_function__ internals>:200, in concatenate(*args, **kwargs) ValueError: all the input array dimensions except for the concatenation axis must match exactly, but along dimension 0, the array at index 0 has size 3 and the array at index 1 has size 2