本文整理汇总了Python中numpy.lib.format.read_array方法的典型用法代码示例。如果您正苦于以下问题:Python format.read_array方法的具体用法?Python format.read_array怎么用?Python format.read_array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy.lib.format
的用法示例。
在下文中一共展示了format.read_array方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_version_2_0
# 需要导入模块: from numpy.lib import format [as 别名]
# 或者: from numpy.lib.format import read_array [as 别名]
def test_version_2_0():
f = BytesIO()
# requires more than 2 byte for header
dt = [(("%d" % i) * 100, float) for i in range(500)]
d = np.ones(1000, dtype=dt)
format.write_array(f, d, version=(2, 0))
with warnings.catch_warnings(record=True) as w:
warnings.filterwarnings('always', '', UserWarning)
format.write_array(f, d)
assert_(w[0].category is UserWarning)
# check alignment of data portion
f.seek(0)
header = f.readline()
assert_(len(header) % format.ARRAY_ALIGN == 0)
f.seek(0)
n = format.read_array(f)
assert_array_equal(d, n)
# 1.0 requested but data cannot be saved this way
assert_raises(ValueError, format.write_array, f, d, (1, 0))
示例2: test_version_2_0
# 需要导入模块: from numpy.lib import format [as 别名]
# 或者: from numpy.lib.format import read_array [as 别名]
def test_version_2_0():
f = BytesIO()
# requires more than 2 byte for header
dt = [(("%d" % i) * 100, float) for i in range(500)]
d = np.ones(1000, dtype=dt)
format.write_array(f, d, version=(2, 0))
with warnings.catch_warnings(record=True) as w:
warnings.filterwarnings('always', '', UserWarning)
format.write_array(f, d)
assert_(w[0].category is UserWarning)
f.seek(0)
n = format.read_array(f)
assert_array_equal(d, n)
# 1.0 requested but data cannot be saved this way
assert_raises(ValueError, format.write_array, f, d, (1, 0))
示例3: roundtrip
# 需要导入模块: from numpy.lib import format [as 别名]
# 或者: from numpy.lib.format import read_array [as 别名]
def roundtrip(arr):
f = BytesIO()
format.write_array(f, arr)
f2 = BytesIO(f.getvalue())
arr2 = format.read_array(f2)
return arr2
示例4: roundtrip_randsize
# 需要导入模块: from numpy.lib import format [as 别名]
# 或者: from numpy.lib.format import read_array [as 别名]
def roundtrip_randsize(arr):
f = BytesIO()
format.write_array(f, arr)
f2 = BytesIOSRandomSize(f.getvalue())
arr2 = format.read_array(f2)
return arr2
示例5: roundtrip_truncated
# 需要导入模块: from numpy.lib import format [as 别名]
# 或者: from numpy.lib.format import read_array [as 别名]
def roundtrip_truncated(arr):
f = BytesIO()
format.write_array(f, arr)
#BytesIO is one byte short
f2 = BytesIO(f.getvalue()[0:-1])
arr2 = format.read_array(f2)
return arr2
示例6: test_read_magic_bad_magic
# 需要导入模块: from numpy.lib import format [as 别名]
# 或者: from numpy.lib.format import read_array [as 别名]
def test_read_magic_bad_magic():
for magic in malformed_magic:
f = BytesIO(magic)
assert_raises(ValueError, format.read_array, f)
示例7: _unpickle_array
# 需要导入模块: from numpy.lib import format [as 别名]
# 或者: from numpy.lib.format import read_array [as 别名]
def _unpickle_array(bytes):
arr = read_array(BytesIO(bytes))
return arr
示例8: test_read_version_1_0_bad_magic
# 需要导入模块: from numpy.lib import format [as 别名]
# 或者: from numpy.lib.format import read_array [as 别名]
def test_read_version_1_0_bad_magic():
for magic in bad_version_magic + malformed_magic:
f = BytesIO(magic)
yield raises(ValueError)(format.read_array), f