Table.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:LTTL 作者: axanthos 项目源码 文件源码
def to_numpy(self):
        """Return a numpy array with the content of a crosstab"""

        # Set numpy table type based on the crosstab's type...
        if isinstance(self, IntPivotCrosstab):
            np_type = np.dtype(np.int32)
        elif isinstance(self, PivotCrosstab):
            np_type = np.dtype(np.float32)

        # Initialize numpy table...
        np_table = np.empty([len(self.row_ids), len(self.col_ids)], np_type)
        np_table.fill(self.missing or 0)

        # Fill and return numpy table...
        for row_idx in xrange(len(self.row_ids)):
            for col_idx in xrange(len(self.col_ids)):
                try:
                    np_table[row_idx][col_idx] = self.values[
                        (self.row_ids[row_idx], self.col_ids[col_idx])
                    ]
                except KeyError:
                    pass
        return np_table

    # TODO: test.
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号