为什么一个numpy数组有96个字节的开销? [英] Why does a numpy array have 96 bytes of overhead?
本文介绍了为什么一个numpy数组有96个字节的开销?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我使用一个简单且空的numpy数组,我可以看到它有96个字节的开销,
If I take a simply and empty numpy array i can see it has 96 bytes of overhead,
>>> sys.getsizeof( np.array([]) )
96
那96个字节存储了什么?
What is that 96 bytes storing? Where in the C source for numpy or Python 3 (cpython) is this set up?
推荐答案
数组在 numpy/core/include/numpy/ndarraytypes.h
请参阅: https://github.com. com/numpy/numpy/blob/master/numpy/core/include/numpy/ndarraytypes.h
看起来它有多个指针,维数和PyObject_HEAD,所有这些指针总数可能等于您看到的字节数.
Looks like it has several pointers, number of dimensions and PyObject_HEAD, which all may in total count to number of bytes you see.
/*
* The main array object structure.
*/
/* This struct will be moved to a private header in a future release */
typedef struct tagPyArrayObject_fields {
PyObject_HEAD
/* Pointer to the raw data buffer */
char *data;
/* The number of dimensions, also called 'ndim' */
int nd;
/* The size in each dimension, also called 'shape' */
npy_intp *dimensions;
/*
* Number of bytes to jump to get to the
* next element in each dimension
*/
npy_intp *strides;
PyObject *base;
/* Pointer to type structure */
PyArray_Descr *descr;
/* Flags describing array -- see below */
int flags;
/* For weak references */
PyObject *weakreflist;
} PyArrayObject_fields;
这篇关于为什么一个numpy数组有96个字节的开销?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文