當前位置: 首頁>>代碼示例>>Python>>正文


Python compat.asbytes_nested方法代碼示例

本文整理匯總了Python中numpy.compat.asbytes_nested方法的典型用法代碼示例。如果您正苦於以下問題:Python compat.asbytes_nested方法的具體用法?Python compat.asbytes_nested怎麽用?Python compat.asbytes_nested使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy.compat的用法示例。


在下文中一共展示了compat.asbytes_nested方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_fillvalue_conversion

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asbytes_nested [as 別名]
def test_fillvalue_conversion(self):
        # Tests the behavior of fill_value during conversion
        # We had a tailored comment to make sure special attributes are
        # properly dealt with
        a = array(asbytes_nested(['3', '4', '5']))
        a._optinfo.update({'comment':"updated!"})

        b = array(a, dtype=int)
        assert_equal(b._data, [3, 4, 5])
        assert_equal(b.fill_value, default_fill_value(0))

        b = array(a, dtype=float)
        assert_equal(b._data, [3, 4, 5])
        assert_equal(b.fill_value, default_fill_value(0.))

        b = a.astype(int)
        assert_equal(b._data, [3, 4, 5])
        assert_equal(b.fill_value, default_fill_value(0))
        assert_equal(b._optinfo['comment'], "updated!")

        b = a.astype([('a', '|S3')])
        assert_equal(b['a']._data, a._data)
        assert_equal(b['a'].fill_value, a.fill_value) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:25,代碼來源:test_core.py

示例2: test_from_string_array

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asbytes_nested [as 別名]
def test_from_string_array(self):
        A = np.array(asbytes_nested([['abc', 'foo'],
                                     ['long   ', '0123456789']]))
        assert_equal(A.dtype.type, np.string_)
        B = np.char.array(A)
        assert_array_equal(B, A)
        assert_equal(B.dtype, A.dtype)
        assert_equal(B.shape, A.shape)
        B[0, 0] = 'changed'
        assert_(B[0, 0] != A[0, 0])
        C = np.char.asarray(A)
        assert_array_equal(C, A)
        assert_equal(C.dtype, A.dtype)
        C[0, 0] = 'changed again'
        assert_(C[0, 0] != B[0, 0])
        assert_(C[0, 0] == A[0, 0]) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:18,代碼來源:test_defchararray.py

示例3: test_lstrip

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asbytes_nested [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) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:19,代碼來源:test_defchararray.py

示例4: test_replace

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asbytes_nested [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) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:19,代碼來源:test_defchararray.py

示例5: test_rjust

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asbytes_nested [as 別名]
def test_rjust(self):
        assert_(issubclass(self.A.rjust(10).dtype.type, np.string_))

        C = self.A.rjust([10, 20])
        assert_array_equal(np.char.str_len(C), [[10, 20], [10, 20], [12, 20]])

        C = self.A.rjust(20, asbytes('#'))
        assert_(np.all(C.startswith(asbytes('#'))))
        assert_array_equal(C.endswith(asbytes('#')),
                           [[False, True], [False, False], [False, False]])

        C = np.char.rjust(asbytes('FOO'), [[10, 20], [15, 8]])
        tgt = asbytes_nested([['       FOO', '                 FOO'],
                              ['            FOO', '     FOO']])
        assert_(issubclass(C.dtype.type, np.string_))
        assert_array_equal(C, tgt) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:18,代碼來源:test_defchararray.py

示例6: test_rstrip

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asbytes_nested [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) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:21,代碼來源:test_defchararray.py

示例7: test_strip

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asbytes_nested [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) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:19,代碼來源:test_defchararray.py

示例8: test_fillvalue_conversion

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asbytes_nested [as 別名]
def test_fillvalue_conversion(self):
        "Tests the behavior of fill_value during conversion"
        # We had a tailored comment to make sure special attributes are properly
        # dealt with
        a = array(asbytes_nested(['3', '4', '5']))
        a._optinfo.update({'comment':"updated!"})
        #
        b = array(a, dtype=int)
        assert_equal(b._data, [3, 4, 5])
        assert_equal(b.fill_value, default_fill_value(0))
        #
        b = array(a, dtype=float)
        assert_equal(b._data, [3, 4, 5])
        assert_equal(b.fill_value, default_fill_value(0.))
        #
        b = a.astype(int)
        assert_equal(b._data, [3, 4, 5])
        assert_equal(b.fill_value, default_fill_value(0))
        assert_equal(b._optinfo['comment'], "updated!")
        #
        b = a.astype([('a', '|S3')])
        assert_equal(b['a']._data, a._data)
        assert_equal(b['a'].fill_value, a.fill_value) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:25,代碼來源:test_core.py

示例9: test_lstrip

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asbytes_nested [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']]) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:18,代碼來源:test_defchararray.py

示例10: test_replace

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asbytes_nested [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']]) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:19,代碼來源:test_defchararray.py

示例11: test_rstrip

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asbytes_nested [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']]) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:18,代碼來源:test_defchararray.py

示例12: test_strip

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asbytes_nested [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']]) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:18,代碼來源:test_defchararray.py

示例13: test_fillvalue_conversion

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asbytes_nested [as 別名]
def test_fillvalue_conversion(self):
        # Tests the behavior of fill_value during conversion
        # We had a tailored comment to make sure special attributes are
        # properly dealt with
        a = array(asbytes_nested(['3', '4', '5']))
        a._optinfo.update({'comment':"updated!"})
        #
        b = array(a, dtype=int)
        assert_equal(b._data, [3, 4, 5])
        assert_equal(b.fill_value, default_fill_value(0))
        #
        b = array(a, dtype=float)
        assert_equal(b._data, [3, 4, 5])
        assert_equal(b.fill_value, default_fill_value(0.))
        #
        b = a.astype(int)
        assert_equal(b._data, [3, 4, 5])
        assert_equal(b.fill_value, default_fill_value(0))
        assert_equal(b._optinfo['comment'], "updated!")
        #
        b = a.astype([('a', '|S3')])
        assert_equal(b['a']._data, a._data)
        assert_equal(b['a'].fill_value, a.fill_value) 
開發者ID:pfchai,項目名稱:ImageFusion,代碼行數:25,代碼來源:test_core.py

示例14: test_no_delimiter

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asbytes_nested [as 別名]
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'])) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:9,代碼來源:test__iotools.py

示例15: test_space_delimiter

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asbytes_nested [as 別名]
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'])) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:9,代碼來源:test__iotools.py


注:本文中的numpy.compat.asbytes_nested方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。