python – numpy内部存储数组的大小吗?

python – numpy内部存储数组的大小吗?,第1张

概述从 here的numpy数组的规范: typedef struct PyArrayObject { PyObject_HEAD char *data; int nd; npy_intp *dimensions; npy_intp *strides; PyObject *base; PyArray_Descr *descr; int f 从 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数组的规范时,我没有看到它存储数组的元素数量.那是真的吗?

不存储的优点是什么?

谢谢.

解决方法 大小(即数组中元素的总数)计算为数组维度中值的乘积.该数组的长度为nd.

在实现numpy核心的C代码中,您将发现宏PyArray_SIZE(obj)的许多用法.这是宏的定义:

#define PyArray_SIZE(m) PyArray_MultiplyList(PyArray_Dims(m),PyArray_NDIM(m))

不存储它的优点是不存储冗余数据.

总结

以上是内存溢出为你收集整理的python – numpy内部存储数组的大小吗?全部内容,希望文章能够帮你解决python – numpy内部存储数组的大小吗?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1193733.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存