Append/concatenate Numpy array to Numpy array
<p>I have two np arrays, one is 1 dimensional, and the other it between 0 and 8 dimensional.  I'm trying to append the multidimensional array onto the other array, as you would with a list.  I've tried <code>np.append(1dim, multidim)</code> and <code>np.concatenate([1dim, multidim])</code> but neither have worked.</p>

<pre><code>[-33.752, 150.902, 38.022, 203.0, 1.0]

[[ -33.75   150.9     39.805    0.       1.   ]
 [ -33.75   150.902   44.697    1.       1.   ]
 [ -33.75   150.905   49.054    2.       1.   ]
 [ -33.752  150.905   39.062  204.       1.   ]
 [ -33.755  150.905   40.698  406.       1.   ]
 [ -33.755  150.902   37.512  405.       1.   ]
 [ -33.755  150.9     36.249  404.       1.   ]
 [ -33.752  150.9     36.627  202.       1.   ]]
</code></pre>

<p>to become:</p>

<pre><code>[-33.752, 150.902, 38.022, 203.0, 1.0],
 [ -33.75   150.9     39.805    0.       1.   ]
 [ -33.75   150.902   44.697    1.       1.   ]
 [ -33.75   150.905   49.054    2.       1.   ]
 [ -33.752  150.905   39.062  204.       1.   ]
 [ -33.755  150.905   40.698  406.       1.   ]
 [ -33.755  150.902   37.512  405.       1.   ]
 [ -33.755  150.9     36.249  404.       1.   ]
 [ -33.752  150.9     36.627  202.       1.   ]]
</code></pre>

<p>I would like to be able to reference the multidim array by using <code>1dim[1]</code></p>

<p>Your example output shows a (1x8) array concatenated with an (Nx8) array to form an (N+1 x 8) array. </p>

<p>If you want to create a "thing" where the first element is the 1-D array and the second element is the N-D array, a list or tuple is your bet. Numpy doesn't really have a great facility for this.</p>

<p>If you want to create an array that is the combination of the two 2D, based on your example, <code>np.vstack([flat_array, big_array])</code> will do that.</p>

<p>By the way, when describing the number of dimensions something has, array.ndim is the same as len(array.shape). Note that an array with 5 rows and 8 columns is two dimensional in the context of numpy.</p>

python numpy