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>The size (that is, the total number of elements in the array) is computed as the product of the values in the array <code>dimensions</code>.  The length of that array is <code>nd</code>.</p>

<p>In the C code that implements the core of numpy, you'll find many uses of the macro <code>PyArray_SIZE(obj)</code>.  Here's the definition of that macro:</p>

<pre><code>#define PyArray_SIZE(m) PyArray_MultiplyList(PyArray_DIMS(m), PyArray_NDIM(m))
</code></pre>

<p>The advantage of not storing it is, well, not storing redundant data.</p>

python c numpy