Combining arrays with:
np.concatenate()
np.hstack()
np.vstack()
np.c_[]
np.r_[]
In [1]:
import numpy as np
In [2]:
a = np.array([[1],[2],[3]])
b = np.array([[4],[5],[6]])
In [3]:
a.shape
Out[3]:
In [4]:
a[1]
Out[4]:
In [5]:
a
Out[5]:
In [6]:
b
Out[6]:
For column vectors:
np.concatenate((a,b), axis=1)
np.hstack([a,b])
np.c_[a,b]
yield the same
and
np.concatenate((a,b), axis=0)
np.vstack([a,b])
np.r_[a,b]
yield the same
In [7]:
np.concatenate((a,b))
Out[7]:
In [8]:
np.concatenate((a,b), axis=0)
Out[8]:
In [9]:
np.concatenate((a,b), axis=1)
Out[9]:
In [10]:
np.hstack([a,b])
Out[10]:
In [11]:
np.c_[a,b]
Out[11]:
In [12]:
np.vstack([a,b])
Out[12]:
In [13]:
np.vstack([a,b]).T
Out[13]:
In [14]:
np.r_[a,b]
Out[14]:
In [15]:
c = np.array([1,2,3])
d = np.array([4,5,6])
In [16]:
c.shape
Out[16]:
In [17]:
c
Out[17]:
In [18]:
d
Out[18]:
In [19]:
np.concatenate((c,d))
Out[19]:
In [20]:
np.concatenate((c,d), axis=0)
Out[20]:
In [21]:
np.concatenate((c,d), axis=1)
For row vectors:
np.concatenate((c,d), axis=0)
np.hstack([c,d])
np.r_[c,d]
yield the same
In [22]:
np.hstack((c,d))
Out[22]:
In [23]:
np.r_[c,d]
Out[23]:
In [24]:
np.vstack((c,d))
Out[24]:
In [25]:
np.vstack((c,d)).T
Out[25]:
In [26]:
np.c_[c,d]
Out[26]: