numpy是否在内部存储数组的大小?

编程入门 行业动态 更新时间:2024-10-24 00:24:16
本文介绍了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数组的规范时,我看不到它存储了数组中元素的数量.是真的吗?

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?

不存储它的好处是什么?

What is the advantage of not storing that?

谢谢.

推荐答案

大小(即数组中元素的总数)计算为数组dimensions中值的乘积.该数组的长度为nd.

The size (that is, the total number of elements in the array) is computed as the product of the values in the array dimensions. The length of that array is nd.

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

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

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

不存储它的好处是,不存储冗余数据.

The advantage of not storing it is, well, not storing redundant data.

更多推荐

numpy是否在内部存储数组的大小?

本文发布于:2023-11-25 15:43:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630348.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   在内部   大小   numpy

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!