本文整理匯總了Python中numpy.lib.format.ARRAY_ALIGN屬性的典型用法代碼示例。如果您正苦於以下問題:Python format.ARRAY_ALIGN屬性的具體用法?Python format.ARRAY_ALIGN怎麽用?Python format.ARRAY_ALIGN使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類numpy.lib.format
的用法示例。
在下文中一共展示了format.ARRAY_ALIGN屬性的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_version_2_0
# 需要導入模塊: from numpy.lib import format [as 別名]
# 或者: from numpy.lib.format import ARRAY_ALIGN [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_read_array_header_1_0
# 需要導入模塊: from numpy.lib import format [as 別名]
# 或者: from numpy.lib.format import ARRAY_ALIGN [as 別名]
def test_read_array_header_1_0():
s = BytesIO()
arr = np.ones((3, 6), dtype=float)
format.write_array(s, arr, version=(1, 0))
s.seek(format.MAGIC_LEN)
shape, fortran, dtype = format.read_array_header_1_0(s)
assert_(s.tell() % format.ARRAY_ALIGN == 0)
assert_((shape, fortran, dtype) == ((3, 6), False, float))
示例3: test_read_array_header_2_0
# 需要導入模塊: from numpy.lib import format [as 別名]
# 或者: from numpy.lib.format import ARRAY_ALIGN [as 別名]
def test_read_array_header_2_0():
s = BytesIO()
arr = np.ones((3, 6), dtype=float)
format.write_array(s, arr, version=(2, 0))
s.seek(format.MAGIC_LEN)
shape, fortran, dtype = format.read_array_header_2_0(s)
assert_(s.tell() % format.ARRAY_ALIGN == 0)
assert_((shape, fortran, dtype) == ((3, 6), False, float))