Difference between single and double bracket Numpy array?
<p>What is the difference between these two numpy objects?</p>

<pre><code>import numpy as np
np.array([[0,0,0,0]])
np.array([0,0,0,0])
</code></pre>

<p>The difference between single and double brackets starts with lists:</p>

<pre><code>In [91]: ll=[0,1,2]
In [92]: ll1=[[0,1,2]]
In [93]: len(ll)
Out[93]: 3
In [94]: len(ll1)
Out[94]: 1
In [95]: len(ll1[0])
Out[95]: 3
</code></pre>

<p><code>ll</code> is a list of 3 items.  <code>ll1</code> is a list of 1 item; that item is another list.  Remember, a list can contain a variety of different objects, numbers, strings, other lists, etc.</p>

<p>Your 2 expressions effectively make arrays from two such lists</p>

<pre><code>In [96]: np.array(ll)
Out[96]: array([0, 1, 2])
In [97]: _.shape
Out[97]: (3,)
In [98]: np.array(ll1)
Out[98]: array([[0, 1, 2]])
In [99]: _.shape
Out[99]: (1, 3)
</code></pre>

<p>Here the list of lists has been turned into a 2d array.  In a subtle way <code>numpy</code> blurs the distinction between the list and the nested list, since the difference between the two arrays lies in their shape, not a fundamental structure.  <code>array(ll)[None,:]</code> produces the <code>(1,3)</code> version, while <code>array(ll1).ravel()</code> produces a <code>(3,)</code> version.</p>

<p>In the end result the difference between single and double brackets is a difference in the number of array dimensions, but we shouldn't loose sight of the fact that Python first creates different lists.</p>

python numpy