Does numpy internally store size of an array?
<p>From specification of a numpy array at <a href="http://docs.scipy.org/doc/numpy-1.10.0/reference/c-api.types-and-structures.html#c.PyArrayObject" rel="nofollow">here</a>:</p>

<pre><code>typedef struct PyArrayObject {
    PyObject_HEAD
    char *data;
    int nd;
    npy_intp *dimensions;
    npy_intp *strides;
    PyObject *base;
    PyArray_Descr *descr;
    int flags;
    PyObject *weakreflist;
} PyArrayObject;
</code></pre>

<p>When I look at the specification of a numpy array, I don't see that it stores number of elements of the array. Is that really the case?</p>

<p>What is the advantage of not storing that?</p>

<p>Thank you.</p>

<p>Look at <code>PyArray_ArrayDescr *PyArray_Descr.subarray</code>:</p>

<blockquote>
  <p>If this is non- NULL, then this data-type descriptor is a C-style
  contiguous array of another data-type descriptor. In other-words, each
  element that this descriptor describes is actually an array of some
  other base descriptor. This is most useful as the data-type descriptor
  for a field in another data-type descriptor. The fields member should
  be NULL if this is non- NULL (the fields member of the base descriptor
  can be non- NULL however). The PyArray_ArrayDescr structure is defined
  using</p>
</blockquote>

<pre><code>typedef struct {
    PyArray_Descr *base;
    PyObject *shape;      /* &lt;-------- */
} PyArray_ArrayDescr;
</code></pre>

<p>and:</p>

<pre><code>PyObject *PyArray_ArrayDescr.shape
</code></pre>

<blockquote>
  <p>The shape (always C-style contiguous) of the sub-array as a Python tuple.</p>
</blockquote>

python c numpy