来自 numpy 数组的规范here http://docs.scipy.org/doc/numpy-1.10.0/reference/c-api.types-and-structures.html#c.PyArrayObject:
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 数组的规范时,我没有看到它存储数组元素的数量。真的是这样吗?
不存储它有什么好处?
谢谢。
大小(即数组中元素的总数)计算为数组中值的乘积dimensions
。该数组的长度是nd
.
在实现numpy核心的C代码中,你会发现宏的许多用途PyArray_SIZE(obj)
。这是该宏的定义:
#define PyArray_SIZE(m) PyArray_MultiplyList(PyArray_DIMS(m), PyArray_NDIM(m))
不存储它的优点是不存储冗余数据。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)