1. ndarray.flags:内存布局(layout)
https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.flags.html
>> x = np.random.rand(2, 4)
>> x.flags
C_CONTIGUOUS : True
F_CONTIGUOUS : False
OWNDATA : True
WRITEABLE : True
ALIGNED : True
WRITEBACKIFCOPY : False
UPDATEIFCOPY : False
-
C_CONTIGUOUS:C-style
-
F_CONTIGUOUS:Fortran-style
-
OWNDATA:拥有自己的数据还是从别的对象借来
>> y = x[1, :] >> y.flags['OWNDATA'] False
2. ndarray.__array_interface__
:内存地址
>> x = np.random.rand(2, 4)
>> x.dtype
dtype('float64')
>> x.__array_interface__['data']
(140245892607552, False)
>> x[0].__array_interface__['data]
(140245892607552, False)
>> x[0, :].__array_interface__['data']
(140245892607552, False)
>> x[1].__array_interface__['data']
(140245892607584, False)
# 140245892607584 = 140245892607552 + 4*8
>> x[1, :].__array_interface__['data']
(140245892607584, False)
以上无论是 x
是 x[0]
还是 x[0, :]
,都是 numpy.ndarray
类型,对于 x[0, 0]
则是普通的 numpy.float64,其地址在另外的地址空间中:
>> x[0, 0].__array_interface__['data']
(140245864608576, False)