How can I append a numpy array of N-Length to another array of N-dimensions?
<p><strong>Situation</strong></p>

<p>I assumed this would be easy - but turns out there are a few restrictions. 
I have an empty array, that at this point, is empty and has unknown dimensions.</p>

<pre><code>mainArray = np.array([])
</code></pre>

<p>later on, I want to append arrays to my main array, which are of different lengths.</p>

<p><strong>I have tried</strong></p>

<p>*Please assume all arrays I have attempted to append are the result of <code>np.zeros(n)</code></p>

<p>I have tried <code>np.append()</code> but this does not maintain the correct dimensions (assumes I want a linear array).</p>

<p>I have tried <code>np.concatenate()</code> however, this error </p>

<pre><code>TypeError: only length-1 arrays can be converted to Python scalars
</code></pre>

<p>implies I cannot concatenate to an empty array...?</p>

<p>I have tried <code>np.vstack()</code> but get</p>

<pre><code>ValueError: all the input array dimensions except for the concatenation axis must match exactly
</code></pre>

<p>...which implies I cannot have added arrays of different lengths?</p>

<p><strong>Question</strong></p>

<p>How can I append n-length arrays to an empty n-dimensional array?</p>

<p><strong>update</strong></p>

<p>Here is an example of an output:</p>

<pre><code>[[0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0]]
</code></pre>

<p>Where length of 3 is a variable</p>

<p>One of the key concepts of numpy's ndarray is that it is rectangular: all elements at a given depth have the same length. This allows simple indexing with a tuple of positions in each dimension to be mapped onto a single flat array:</p>

<pre><code>array[x,y,z] #where array.shape = (a,b,c)
#is equivalent to:
array.flat[b*c*x + c*y + z]
</code></pre>

<p>This allows very fast and efficient operation in c for many algorithms.</p>

<p>Numpy does technically support what you want to do, but the implementation is basically reverting functionality back to native lists. The way to do it with numpy is to specify the array <code>dtype=object</code>.</p>

<h2>;TLDR</h2>

<p>Arrays are intended to be created the correct size ahead of time and never change size. The functionality does exist, but it bypasses some of the advantages of using numpy arrays in the first place.</p>

python arrays numpy