[英]how to query the memory layout of pandas.dataframe
I want to to query the memory layout of a pandas.dataframe. 我想查询pandas.dataframe的内存布局。 More explicitly, given a dataframe df (say, of the type np.float32), I would like to known if it is column-contiguous or row-contiguous.
更明确地说,给定一个数据帧df(例如,类型为np.float32),我想知道它是列连续的还是行连续的。
you can examine the flags
attribute of the underlying numpy array. 您可以检查基础numpy数组的
flags
属性。 The underlying numpy array can be accessed through the pd.DataFrame.values
可以通过
pd.DataFrame.values
访问基础的numpy数组
example: 例:
import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.random(12).reshape(4,3), columns=list('abc'))
df.values.flags
#outputs:
C_CONTIGUOUS : True
F_CONTIGUOUS : False
OWNDATA : False
WRITEABLE : True
ALIGNED : True
WRITEBACKIFCOPY : False
UPDATEIFCOPY : False
As you can see from the output, in this case the data is row-contiguous ( C_CONTINUOUS
). 从输出中可以看到,在这种情况下,数据是行连续的(
C_CONTINUOUS
)。 F_CONTINUOUS
signifies that the data is column-contiguous F_CONTINUOUS
表示数据是列连续的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.