props.py 文件源码

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

项目:steno3dpy 作者: aranzgeo 项目源码 文件源码
def array_serializer(data, **kwargs):
    """Convert the array data to a serialized binary format"""
    if isinstance(data.flatten()[0], np.floating):
        use_dtype = '<f4'
        nan_mask = ~np.isnan(data)
        assert np.allclose(
                data.astype(use_dtype)[nan_mask], data[nan_mask]), \
            'Converting the type should not screw things up.'
    elif isinstance(data.flatten()[0], np.integer):
        use_dtype = '<i4'
        assert (data.astype(use_dtype) == data).all(), \
            'Converting the type should not screw things up.'
    else:
        raise TypeError('Must be a float or an int: {}'.format(data.dtype))

    data_file = NamedTemporaryFile('rb+', suffix='.dat')
    data.astype(use_dtype).tofile(data_file.file)
    data_file.seek(0)
    return FileProp(data_file, use_dtype)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号