当前位置: 首页>>代码示例>>Python>>正文


Python format.read_magic方法代码示例

本文整理汇总了Python中numpy.lib.format.read_magic方法的典型用法代码示例。如果您正苦于以下问题:Python format.read_magic方法的具体用法?Python format.read_magic怎么用?Python format.read_magic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpy.lib.format的用法示例。


在下文中一共展示了format.read_magic方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_read_magic

# 需要导入模块: from numpy.lib import format [as 别名]
# 或者: from numpy.lib.format import read_magic [as 别名]
def test_read_magic():
    s1 = BytesIO()
    s2 = BytesIO()

    arr = np.ones((3, 6), dtype=float)

    format.write_array(s1, arr, version=(1, 0))
    format.write_array(s2, arr, version=(2, 0))

    s1.seek(0)
    s2.seek(0)

    version1 = format.read_magic(s1)
    version2 = format.read_magic(s2)

    assert_(version1 == (1, 0))
    assert_(version2 == (2, 0))

    assert_(s1.tell() == format.MAGIC_LEN)
    assert_(s2.tell() == format.MAGIC_LEN) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:22,代码来源:test_format.py

示例2: test_read_magic_bad_magic

# 需要导入模块: from numpy.lib import format [as 别名]
# 或者: from numpy.lib.format import read_magic [as 别名]
def test_read_magic_bad_magic():
    for magic in malformed_magic:
        f = BytesIO(magic)
        yield raises(ValueError)(format.read_magic), f 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:6,代码来源:test_format.py

示例3: _get_info

# 需要导入模块: from numpy.lib import format [as 别名]
# 或者: from numpy.lib.format import read_magic [as 别名]
def _get_info(self):
        from numpy.lib import format
        with self.f as fp:
            version = format.read_magic(fp)
            format._check_version(version)

            shape, fortran_order, dtype = format._read_array_header(fp, version)
            self.shape = shape
            self.dtype = dtype
            self.order = 'F' if fortran_order else 'C'
            self.offset = fp.tell() 
开发者ID:intake,项目名称:intake,代码行数:13,代码来源:npy.py

示例4: _read_header

# 需要导入模块: from numpy.lib import format [as 别名]
# 或者: from numpy.lib.format import read_magic [as 别名]
def _read_header(self):
        with open(self.path, 'rb') as fp:
            version = format.read_magic(fp)
            try:
                format._check_version(version)
            except ValueError:
                raise ValueError('Invalid file format.')
            header_data = format._read_array_header(fp, version)
            self.shape, self.fortran_order, self.dtype = header_data 
开发者ID:bsc-wdc,项目名称:dislib,代码行数:11,代码来源:_data.py

示例5: load_npy_file

# 需要导入模块: from numpy.lib import format [as 别名]
# 或者: from numpy.lib.format import read_magic [as 别名]
def load_npy_file(path, block_size):
    """ Loads a file in npy format (must be 2-dimensional).

    Parameters
    ----------
    path : str
        Path to the npy file.
    block_size : tuple (int, int)
        Block size of the resulting ds-array.

    Returns
    -------
    x : ds-array
    """
    try:
        fid = open(path, "rb")
        version = format.read_magic(fid)
        format._check_version(version)
        shape, fortran_order, dtype = format._read_array_header(fid, version)

        if fortran_order:
            raise ValueError("Fortran order not supported for npy files")

        if len(shape) != 2:
            raise ValueError("Array is not 2-dimensional")

        if block_size[0] > shape[0] or block_size[1] > shape[1]:
            raise ValueError("Block size is larger than the array")

        blocks = []
        n_blocks = int(ceil(shape[1] / block_size[1]))

        for i in range(0, shape[0], block_size[0]):
            read_count = min(block_size[0], shape[0] - i)
            read_size = int(read_count * shape[1] * dtype.itemsize)
            data = fid.read(read_size)
            out_blocks = [object() for _ in range(n_blocks)]
            _read_from_buffer(data, dtype, shape[1], block_size[1], out_blocks)
            blocks.append(out_blocks)

        return Array(blocks=blocks, top_left_shape=block_size,
                     reg_shape=block_size, shape=shape, sparse=False)
    finally:
        fid.close() 
开发者ID:bsc-wdc,项目名称:dislib,代码行数:46,代码来源:io.py


注:本文中的numpy.lib.format.read_magic方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。