【发布时间】:2016-09-07 19:41:13
【问题描述】:
来自here 的 numpy 数组规范:
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;
当我查看 numpy 数组的规范时,我没有看到它存储了数组元素的数量。真的是这样吗?
不存储有什么好处?
谢谢。
【问题讨论】:
-
然而,它看起来好像存储了维度和步幅的数组。在大多数涉及数组操作的实现中,这是实际需要的信息,而不是项目总数,这无助于您系统地访问它们。
-
我想我现在明白了。当数组的大小很大时,将维度相乘得到大小只需要一小部分时间即可完成整个计算。