Why does the shape of a 1D array not show the number of rows as 1?
<p>I know that numpy array has a method called shape that returns [No.of rows, No.of columns], and shape[0] gives you the number of rows, shape[1] gives you the number of columns. </p>

<pre><code>a = numpy.array([[1,2,3,4], [2,3,4,5]])
a.shape
&gt;&gt; [2,4]
a.shape[0]
&gt;&gt; 2
a.shape[1]
&gt;&gt; 4
</code></pre>

<p>However, if my array only have one row, then it returns [No.of columns, ]. And shape[1] will be out of the index. For example</p>

<pre><code>a = numpy.array([1,2,3,4])
a.shape
&gt;&gt; [4,]
a.shape[0]
&gt;&gt; 4    //this is the number of column
a.shape[1]
&gt;&gt; Error out of index
</code></pre>

<p>Now how do I get the number of rows of an numpy array if the array may have only one row?</p>

<p>Thank you</p>