How can I initialize an empty Numpy array with a given number of dimensions?
<p>I basically want to initialize an empty 6-tensor, like this:</p>

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

<p>Is there a better way than writing the brackets explicitly?</p>

<p>You can do something like <code>np.empty(shape = [1] * (dimensions - 1) + [0])</code>.
Example:</p>

<pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt; a = np.array([[[[[[]]]]]])
&gt;&gt;&gt; b = np.empty(shape = [1] * 5 + [0])
&gt;&gt;&gt; a.shape == b.shape
True
</code></pre>

python arrays numpy