本文整理汇总了Python中numpy.compat.asbytes_nested函数的典型用法代码示例。如果您正苦于以下问题:Python asbytes_nested函数的具体用法?Python asbytes_nested怎么用?Python asbytes_nested使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了asbytes_nested函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_no_delimiter
def test_no_delimiter(self):
"Test LineSplitter w/o delimiter"
strg = asbytes(" 1 2 3 4 5 # test")
test = LineSplitter()(strg)
assert_equal(test, asbytes_nested(['1', '2', '3', '4', '5']))
test = LineSplitter('')(strg)
assert_equal(test, asbytes_nested(['1', '2', '3', '4', '5']))
示例2: test_partition
def test_partition(self):
P = self.A.partition(asbytes_nested(['3', 'M']))
tgt = asbytes_nested([[(' abc ', '', ''), ('', '', '')],
[('12', '3', '45'), ('', 'M', 'ixedCase')],
[('12', '3', ' \t 345 \0 '), ('UPPER', '', '')]])
assert_(issubclass(P.dtype.type, np.string_))
assert_array_equal(P, tgt)
示例3: test_set_elements
def test_set_elements(self):
base = self.base.copy()
# Set an element to mask .....................
mbase = base.view(mrecarray).copy()
mbase[-2] = masked
assert_equal(
mbase._mask.tolist(),
np.array([(0, 0, 0), (1, 1, 1), (0, 0, 0), (1, 1, 1), (1, 1, 1)],
dtype=bool))
# Used to be mask, now it's recordmask!
assert_equal(mbase.recordmask, [0, 1, 0, 1, 1])
# Set slices .................................
mbase = base.view(mrecarray).copy()
mbase[:2] = (5, 5, 5)
assert_equal(mbase.a._data, [5, 5, 3, 4, 5])
assert_equal(mbase.a._mask, [0, 0, 0, 0, 1])
assert_equal(mbase.b._data, [5., 5., 3.3, 4.4, 5.5])
assert_equal(mbase.b._mask, [0, 0, 0, 0, 1])
assert_equal(mbase.c._data,
asbytes_nested(['5', '5', 'three', 'four', 'five']))
assert_equal(mbase.b._mask, [0, 0, 0, 0, 1])
mbase = base.view(mrecarray).copy()
mbase[:2] = masked
assert_equal(mbase.a._data, [1, 2, 3, 4, 5])
assert_equal(mbase.a._mask, [1, 1, 0, 0, 1])
assert_equal(mbase.b._data, [1.1, 2.2, 3.3, 4.4, 5.5])
assert_equal(mbase.b._mask, [1, 1, 0, 0, 1])
assert_equal(mbase.c._data,
asbytes_nested(['one', 'two', 'three', 'four', 'five']))
assert_equal(mbase.b._mask, [1, 1, 0, 0, 1])
示例4: test_space_delimiter
def test_space_delimiter(self):
"Test space delimiter"
strg = asbytes(" 1 2 3 4 5 # test")
test = LineSplitter(asbytes(' '))(strg)
assert_equal(test, asbytes_nested(['1', '2', '3', '4', '', '5']))
test = LineSplitter(asbytes(' '))(strg)
assert_equal(test, asbytes_nested(['1 2 3 4', '5']))
示例5: test_rpartition
def test_rpartition(self):
P = self.A.rpartition(asbytes_nested(['3', 'M']))
assert_(issubclass(P.dtype.type, np.string_))
assert_array_equal(P, asbytes_nested([
[('', '', ' abc '), ('', '', '')],
[('12', '3', '45'), ('', 'M', 'ixedCase')],
[('123 \t ', '3', '45 \0 '), ('', '', 'UPPER')]]))
示例6: test_space_delimiter
def test_space_delimiter(self):
"Test space delimiter"
strg = asbytes(" 1 2 3 4 5 # test")
test = LineSplitter(asbytes(" "))(strg)
assert_equal(test, asbytes_nested(["1", "2", "3", "4", "", "5"]))
test = LineSplitter(asbytes(" "))(strg)
assert_equal(test, asbytes_nested(["1 2 3 4", "5"]))
示例7: test_no_delimiter
def test_no_delimiter(self):
"Test LineSplitter w/o delimiter"
strg = asbytes(" 1 2 3 4 5 # test")
test = LineSplitter()(strg)
assert_equal(test, asbytes_nested(["1", "2", "3", "4", "5"]))
test = LineSplitter("")(strg)
assert_equal(test, asbytes_nested(["1", "2", "3", "4", "5"]))
示例8: test_variable_fixed_width
def test_variable_fixed_width(self):
strg = asbytes(" 1 3 4 5 6# test")
test = LineSplitter((3, 6, 6, 3))(strg)
assert_equal(test, asbytes_nested(["1", "3", "4 5", "6"]))
#
strg = asbytes(" 1 3 4 5 6# test")
test = LineSplitter((6, 6, 9))(strg)
assert_equal(test, asbytes_nested(["1", "3 4", "5 6"]))
示例9: test_tab_delimiter
def test_tab_delimiter(self):
"Test tab delimiter"
strg = asbytes(" 1\t 2\t 3\t 4\t 5 6")
test = LineSplitter(asbytes("\t"))(strg)
assert_equal(test, asbytes_nested(["1", "2", "3", "4", "5 6"]))
strg = asbytes(" 1 2\t 3 4\t 5 6")
test = LineSplitter(asbytes("\t"))(strg)
assert_equal(test, asbytes_nested(["1 2", "3 4", "5 6"]))
示例10: test_partition
def test_partition(self):
if sys.version_info >= (2, 5):
P = self.A.partition(asbytes_nested(['3', 'M']))
assert issubclass(P.dtype.type, np.string_)
assert_array_equal(P, asbytes_nested([
[(' abc ', '', ''), ('', '', '')],
[('12', '3', '45'), ('', 'M', 'ixedCase')],
[('12', '3', ' \t 345 \0 '), ('UPPER', '', '')]]))
示例11: test_other_delimiter
def test_other_delimiter(self):
"Test LineSplitter on delimiter"
strg = asbytes("1,2,3,4,,5")
test = LineSplitter(asbytes(","))(strg)
assert_equal(test, asbytes_nested(["1", "2", "3", "4", "", "5"]))
#
strg = asbytes(" 1,2,3,4,,5 # test")
test = LineSplitter(asbytes(","))(strg)
assert_equal(test, asbytes_nested(["1", "2", "3", "4", "", "5"]))
示例12: test_other_delimiter
def test_other_delimiter(self):
"Test LineSplitter on delimiter"
strg = asbytes("1,2,3,4,,5")
test = LineSplitter(asbytes(','))(strg)
assert_equal(test, asbytes_nested(['1', '2', '3', '4', '', '5']))
#
strg = asbytes(" 1,2,3,4,,5 # test")
test = LineSplitter(asbytes(','))(strg)
assert_equal(test, asbytes_nested(['1', '2', '3', '4', '', '5']))
示例13: test_lapack
def test_lapack(self):
f = FindDependenciesLdd()
depsLibg2c = f.grep_dependencies(lapack_lite.__file__,
asbytes_nested(['libg2c']))
depsLibgfortran = f.grep_dependencies(lapack_lite.__file__,
asbytes_nested(['libgfortran']))
self.assertFalse(len(depsLibg2c)*len(depsLibgfortran) > 0,
"""Both g77 and gfortran runtimes linked in lapack_lite ! This is likely to
cause random crashes and wrong results. See numpy INSTALL.txt for more
information.""")
示例14: test_strip
def test_strip(self):
assert issubclass(self.A.strip().dtype.type, np.string_)
assert_array_equal(
self.A.strip(), asbytes_nested([["abc", ""], ["12345", "MixedCase"], ["123 \t 345", "UPPER"]])
)
assert_array_equal(
self.A.strip(asbytes_nested(["15", "EReM"])),
asbytes_nested([[" abc ", ""], ["234", "ixedCas"], ["23 \t 345 \x00", "UPP"]]),
)
assert issubclass(self.B.strip().dtype.type, np.unicode_)
assert_array_equal(self.B.strip(), [["\u03a3", ""], ["12345", "MixedCase"], ["123 \t 345", "UPPER"]])
示例15: test_constant_fixed_width
def test_constant_fixed_width(self):
"Test LineSplitter w/ fixed-width fields"
strg = asbytes(" 1 2 3 4 5 # test")
test = LineSplitter(3)(strg)
assert_equal(test, asbytes_nested(["1", "2", "3", "4", "", "5", ""]))
#
strg = asbytes(" 1 3 4 5 6# test")
test = LineSplitter(20)(strg)
assert_equal(test, asbytes_nested(["1 3 4 5 6"]))
#
strg = asbytes(" 1 3 4 5 6# test")
test = LineSplitter(30)(strg)
assert_equal(test, asbytes_nested(["1 3 4 5 6"]))