本文整理匯總了Python中numpy.compat.sixu方法的典型用法代碼示例。如果您正苦於以下問題:Python compat.sixu方法的具體用法?Python compat.sixu怎麽用?Python compat.sixu使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy.compat
的用法示例。
在下文中一共展示了compat.sixu方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_lstrip
# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import sixu [as 別名]
def test_lstrip(self):
tgt = asbytes_nested([['abc ', ''],
['12345', 'MixedCase'],
['123 \t 345 \0 ', 'UPPER']])
assert_(issubclass(self.A.lstrip().dtype.type, np.string_))
assert_array_equal(self.A.lstrip(), tgt)
tgt = asbytes_nested([[' abc', ''],
['2345', 'ixedCase'],
['23 \t 345 \x00', 'UPPER']])
assert_array_equal(self.A.lstrip(asbytes_nested(['1', 'M'])), tgt)
tgt = [[sixu('\u03a3 '), ''],
['12345', 'MixedCase'],
['123 \t 345 \0 ', 'UPPER']]
assert_(issubclass(self.B.lstrip().dtype.type, np.unicode_))
assert_array_equal(self.B.lstrip(), tgt)
示例2: test_replace
# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import sixu [as 別名]
def test_replace(self):
R = self.A.replace(asbytes_nested(['3', 'a']),
asbytes_nested(['##########', '@']))
tgt = asbytes_nested([[' abc ', ''],
['12##########45', 'MixedC@se'],
['12########## \t ##########45 \x00', 'UPPER']])
assert_(issubclass(R.dtype.type, np.string_))
assert_array_equal(R, tgt)
if sys.version_info[0] < 3:
# NOTE: b'abc'.replace(b'a', 'b') is not allowed on Py3
R = self.A.replace(asbytes('a'), sixu('\u03a3'))
tgt = [[sixu(' \u03a3bc '), ''],
['12345', sixu('MixedC\u03a3se')],
['123 \t 345 \x00', 'UPPER']]
assert_(issubclass(R.dtype.type, np.unicode_))
assert_array_equal(R, tgt)
示例3: test_rstrip
# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import sixu [as 別名]
def test_rstrip(self):
assert_(issubclass(self.A.rstrip().dtype.type, np.string_))
tgt = asbytes_nested([[' abc', ''],
['12345', 'MixedCase'],
['123 \t 345', 'UPPER']])
assert_array_equal(self.A.rstrip(), tgt)
tgt = asbytes_nested([[' abc ', ''],
['1234', 'MixedCase'],
['123 \t 345 \x00', 'UPP']
])
assert_array_equal(self.A.rstrip(asbytes_nested(['5', 'ER'])), tgt)
tgt = [[sixu(' \u03a3'), ''],
['12345', 'MixedCase'],
['123 \t 345', 'UPPER']]
assert_(issubclass(self.B.rstrip().dtype.type, np.unicode_))
assert_array_equal(self.B.rstrip(), tgt)
示例4: test_strip
# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import sixu [as 別名]
def test_strip(self):
tgt = asbytes_nested([['abc', ''],
['12345', 'MixedCase'],
['123 \t 345', 'UPPER']])
assert_(issubclass(self.A.strip().dtype.type, np.string_))
assert_array_equal(self.A.strip(), tgt)
tgt = asbytes_nested([[' abc ', ''],
['234', 'ixedCas'],
['23 \t 345 \x00', 'UPP']])
assert_array_equal(self.A.strip(asbytes_nested(['15', 'EReM'])), tgt)
tgt = [[sixu('\u03a3'), ''],
['12345', 'MixedCase'],
['123 \t 345', 'UPPER']]
assert_(issubclass(self.B.strip().dtype.type, np.unicode_))
assert_array_equal(self.B.strip(), tgt)
示例5: test_iter_buffering_string
# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import sixu [as 別名]
def test_iter_buffering_string():
# Safe casting disallows shrinking strings
a = np.array(['abc', 'a', 'abcd'], dtype=np.bytes_)
assert_equal(a.dtype, np.dtype('S4'))
assert_raises(TypeError, nditer, a, ['buffered'], ['readonly'],
op_dtypes='S2')
i = nditer(a, ['buffered'], ['readonly'], op_dtypes='S6')
assert_equal(i[0], asbytes('abc'))
assert_equal(i[0].dtype, np.dtype('S6'))
a = np.array(['abc', 'a', 'abcd'], dtype=np.unicode)
assert_equal(a.dtype, np.dtype('U4'))
assert_raises(TypeError, nditer, a, ['buffered'], ['readonly'],
op_dtypes='U2')
i = nditer(a, ['buffered'], ['readonly'], op_dtypes='U6')
assert_equal(i[0], sixu('abc'))
assert_equal(i[0].dtype, np.dtype('U6'))
示例6: test_lstrip
# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import sixu [as 別名]
def test_lstrip(self):
assert_(issubclass(self.A.lstrip().dtype.type, np.string_))
assert_array_equal(self.A.lstrip(), asbytes_nested([
['abc ', ''],
['12345', 'MixedCase'],
['123 \t 345 \0 ', 'UPPER']]))
assert_array_equal(self.A.lstrip(asbytes_nested(['1', 'M'])),
asbytes_nested([
[' abc', ''],
['2345', 'ixedCase'],
['23 \t 345 \x00', 'UPPER']]))
assert_(issubclass(self.B.lstrip().dtype.type, np.unicode_))
assert_array_equal(self.B.lstrip(), [
[sixu('\u03a3 '), ''],
['12345', 'MixedCase'],
['123 \t 345 \0 ', 'UPPER']])
示例7: test_replace
# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import sixu [as 別名]
def test_replace(self):
R = self.A.replace(asbytes_nested(['3', 'a']),
asbytes_nested(['##########', '@']))
assert_(issubclass(R.dtype.type, np.string_))
assert_array_equal(R, asbytes_nested([
[' abc ', ''],
['12##########45', 'MixedC@se'],
['12########## \t ##########45 \x00', 'UPPER']]))
if sys.version_info[0] < 3:
# NOTE: b'abc'.replace(b'a', 'b') is not allowed on Py3
R = self.A.replace(asbytes('a'), sixu('\u03a3'))
assert_(issubclass(R.dtype.type, np.unicode_))
assert_array_equal(R, [
[sixu(' \u03a3bc '), ''],
['12345', sixu('MixedC\u03a3se')],
['123 \t 345 \x00', 'UPPER']])
示例8: test_rstrip
# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import sixu [as 別名]
def test_rstrip(self):
assert_(issubclass(self.A.rstrip().dtype.type, np.string_))
assert_array_equal(self.A.rstrip(), asbytes_nested([
[' abc', ''],
['12345', 'MixedCase'],
['123 \t 345', 'UPPER']]))
assert_array_equal(self.A.rstrip(asbytes_nested(['5', 'ER'])),
asbytes_nested([
[' abc ', ''],
['1234', 'MixedCase'],
['123 \t 345 \x00', 'UPP']]))
assert_(issubclass(self.B.rstrip().dtype.type, np.unicode_))
assert_array_equal(self.B.rstrip(), [
[sixu(' \u03a3'), ''],
['12345', 'MixedCase'],
['123 \t 345', 'UPPER']])
示例9: test_strip
# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import sixu [as 別名]
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(), [
[sixu('\u03a3'), ''],
['12345', 'MixedCase'],
['123 \t 345', 'UPPER']])
示例10: test_iter_buffering_string
# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import sixu [as 別名]
def test_iter_buffering_string():
# Safe casting disallows shrinking strings
a = np.array(['abc', 'a', 'abcd'], dtype=np.bytes_)
assert_equal(a.dtype, np.dtype('S4'));
assert_raises(TypeError, nditer, a, ['buffered'], ['readonly'],
op_dtypes='S2')
i = nditer(a, ['buffered'], ['readonly'], op_dtypes='S6')
assert_equal(i[0], asbytes('abc'))
assert_equal(i[0].dtype, np.dtype('S6'))
a = np.array(['abc', 'a', 'abcd'], dtype=np.unicode)
assert_equal(a.dtype, np.dtype('U4'));
assert_raises(TypeError, nditer, a, ['buffered'], ['readonly'],
op_dtypes='U2')
i = nditer(a, ['buffered'], ['readonly'], op_dtypes='U6')
assert_equal(i[0], sixu('abc'))
assert_equal(i[0].dtype, np.dtype('U6'))
示例11: test_masked_array_repr_unicode
# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import sixu [as 別名]
def test_masked_array_repr_unicode(self):
# Ticket #1256
repr(np.ma.array(sixu("Unicode")))
示例12: test_unicode_object_array
# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import sixu [as 別名]
def test_unicode_object_array():
import sys
if sys.version_info[0] >= 3:
expected = "array(['é'], dtype=object)"
else:
expected = "array([u'\\xe9'], dtype=object)"
x = np.array([sixu('\xe9')], dtype=object)
assert_equal(repr(x), expected)
示例13: content_check
# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import sixu [as 別名]
def content_check(self, ua, ua_scalar, nbytes):
# Check the length of the unicode base type
self.assertTrue(int(ua.dtype.str[2:]) == self.ulen)
# Check the length of the data buffer
self.assertTrue(buffer_length(ua) == nbytes)
# Small check that data in array element is ok
self.assertTrue(ua_scalar == sixu(''))
# Encode to ascii and double check
self.assertTrue(ua_scalar.encode('ascii') == asbytes(''))
# Check buffer lengths for scalars
if ucs4:
self.assertTrue(buffer_length(ua_scalar) == 0)
else:
self.assertTrue(buffer_length(ua_scalar) == 0)
示例14: test_unicode
# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import sixu [as 別名]
def test_unicode():
np.longdouble(sixu("1.2"))
示例15: test_from_object_array_unicode
# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import sixu [as 別名]
def test_from_object_array_unicode(self):
A = np.array([['abc', sixu('Sigma \u03a3')],
['long ', '0123456789']], dtype='O')
self.assertRaises(ValueError, np.char.array, (A,))
B = np.char.array(A, **kw_unicode_true)
assert_equal(B.dtype.itemsize, 10 * np.array('a', 'U').dtype.itemsize)
assert_array_equal(B, [['abc', sixu('Sigma \u03a3')],
['long', '0123456789']])