Let's say we have two arrays
a = [1, 2]
b = [ [A, B, C], [D, E, F] ]
I want to make c = [ [1,A, B, C], [2, D, E, F] ] by combing a & b
How to achieve that?
The amounts of 1st level children are the same in both a and b.
You need to reshape a so it becomes a 2x1 array then you can use hstack to horizontally stack the arrays:
In[13]:
np.hstack([a.reshape((2,1)), b])
Out[13]:
array([['1', 'A', 'B', 'C'],
['2', 'D', 'E', 'F']],
dtype='<U11')
As suggested by numpy master @Divakar, if you slice the array and pass None as one of the axes, you can introduce or reshape the array without the need to reshape:
In[14]:
np.hstack([a[:,None], b])
Out[14]:
array([['1', 'A', 'B', 'C'],
['2', 'D', 'E', 'F']],
dtype='<U11')
It's explained in the docs, look for newaxis example