• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python compat.sixu函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中numpy.compat.sixu函数的典型用法代码示例。如果您正苦于以下问题:Python sixu函数的具体用法?Python sixu怎么用?Python sixu使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了sixu函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_from_object_array_unicode

 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']])
开发者ID:MolecularFlipbook,项目名称:FlipbookApp,代码行数:8,代码来源:test_defchararray.py


示例2: test_replace

    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', '[email protected]'],
                ['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:MolecularFlipbook,项目名称:FlipbookApp,代码行数:17,代码来源:test_defchararray.py


示例3: test_unicode_object_array

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)
开发者ID:bennyrowland,项目名称:numpy,代码行数:8,代码来源:test_arrayprint.py


示例4: test_capitalize

 def test_capitalize(self):
     assert_(issubclass(self.A.capitalize().dtype.type, np.string_))
     assert_array_equal(self.A.capitalize(), asbytes_nested([
             [' abc ', ''],
             ['12345', 'Mixedcase'],
             ['123 \t 345 \0 ', 'Upper']]))
     assert_(issubclass(self.B.capitalize().dtype.type, np.unicode_))
     assert_array_equal(self.B.capitalize(), [
             [sixu(' \u03c3 '), ''],
             ['12345', 'Mixedcase'],
             ['123 \t 345 \0 ', 'Upper']])
开发者ID:MolecularFlipbook,项目名称:FlipbookApp,代码行数:11,代码来源:test_defchararray.py


示例5: setUp

 def setUp(self):
     self.A = np.array([[' abc ', ''],
                        ['12345', 'MixedCase'],
                        ['123 \t 345 \0 ', 'UPPER']]).view(np.chararray)
     self.B = np.array([[sixu(' \u03a3 '), sixu('')],
                        [sixu('12345'), sixu('MixedCase')],
                        [sixu('123 \t 345 \0 '), sixu('UPPER')]]).view(np.chararray)
开发者ID:MolecularFlipbook,项目名称:FlipbookApp,代码行数:7,代码来源:test_defchararray.py


示例6: test_pickle_python2_python3

def test_pickle_python2_python3():
    # Test that loading object arrays saved on Python 2 works both on
    # Python 2 and Python 3 and vice versa
    data_dir = os.path.join(os.path.dirname(__file__), 'data')

    if sys.version_info[0] >= 3:
        xrange = range
    else:
        import __builtin__
        xrange = __builtin__.xrange

    expected = np.array([None, xrange, sixu('\u512a\u826f'),
                         asbytes('\xe4\xb8\x8d\xe8\x89\xaf')],
                        dtype=object)

    for fname in ['py2-objarr.npy', 'py2-objarr.npz',
                  'py3-objarr.npy', 'py3-objarr.npz']:
        path = os.path.join(data_dir, fname)

        for encoding in ['bytes', 'latin1']:
            data_f = np.load(path, encoding=encoding)
            if fname.endswith('.npz'):
                data = data_f['x']
                data_f.close()
            else:
                data = data_f

            if sys.version_info[0] >= 3:
                if encoding == 'latin1' and fname.startswith('py2'):
                    assert_(isinstance(data[3], str))
                    assert_array_equal(data[:-1], expected[:-1])
                    # mojibake occurs
                    assert_array_equal(data[-1].encode(encoding), expected[-1])
                else:
                    assert_(isinstance(data[3], bytes))
                    assert_array_equal(data, expected)
            else:
                assert_array_equal(data, expected)

        if sys.version_info[0] >= 3:
            if fname.startswith('py2'):
                if fname.endswith('.npz'):
                    data = np.load(path)
                    assert_raises(UnicodeError, data.__getitem__, 'x')
                    data.close()
                    data = np.load(path, fix_imports=False, encoding='latin1')
                    assert_raises(ImportError, data.__getitem__, 'x')
                    data.close()
                else:
                    assert_raises(UnicodeError, np.load, path)
                    assert_raises(ImportError, np.load, path,
                                  encoding='latin1', fix_imports=False)
开发者ID:ContinuumIO,项目名称:numpy,代码行数:52,代码来源:test_format.py


示例7: test_from_unicode_array

 def test_from_unicode_array(self):
     A = np.array([['abc', sixu('Sigma \u03a3')],
                   ['long   ', '0123456789']])
     assert_equal(A.dtype.type, np.unicode_)
     B = np.char.array(A)
     assert_array_equal(B, A)
     assert_equal(B.dtype, A.dtype)
     assert_equal(B.shape, A.shape)
     B = np.char.array(A, **kw_unicode_true)
     assert_array_equal(B, A)
     assert_equal(B.dtype, A.dtype)
     assert_equal(B.shape, A.shape)
     def fail():
         B = np.char.array(A, **kw_unicode_false)
     self.assertRaises(UnicodeEncodeError, fail)
开发者ID:MolecularFlipbook,项目名称:FlipbookApp,代码行数:15,代码来源:test_defchararray.py


示例8: content_check

    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)
开发者ID:ArnoldAndersson,项目名称:numpy,代码行数:15,代码来源:test_unicode.py


示例9: 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(), [
             [sixu('\u03a3'), ''],
             ['12345', 'MixedCase'],
             ['123 \t 345', 'UPPER']])
开发者ID:MolecularFlipbook,项目名称:FlipbookApp,代码行数:16,代码来源:test_defchararray.py


示例10: test_upper

 def test_upper(self):
     assert_(issubclass(self.A.upper().dtype.type, np.string_))
     assert_array_equal(self.A.upper(), asbytes_nested([
             [' ABC ', ''],
             ['12345', 'MIXEDCASE'],
             ['123 \t 345 \0 ', 'UPPER']]))
     assert_(issubclass(self.B.upper().dtype.type, np.unicode_))
     assert_array_equal(self.B.upper(), [
             [sixu(' \u03a3 '), sixu('')],
             [sixu('12345'), sixu('MIXEDCASE')],
             [sixu('123 \t 345 \0 '), sixu('UPPER')]])
开发者ID:MolecularFlipbook,项目名称:FlipbookApp,代码行数:11,代码来源:test_defchararray.py


示例11: test_title

 def test_title(self):
     assert_(issubclass(self.A.title().dtype.type, np.string_))
     assert_array_equal(self.A.title(), asbytes_nested([
             [' Abc ', ''],
             ['12345', 'Mixedcase'],
             ['123 \t 345 \0 ', 'Upper']]))
     assert_(issubclass(self.B.title().dtype.type, np.unicode_))
     assert_array_equal(self.B.title(), [
             [sixu(' \u03a3 '), sixu('')],
             [sixu('12345'), sixu('Mixedcase')],
             [sixu('123 \t 345 \0 '), sixu('Upper')]])
开发者ID:MolecularFlipbook,项目名称:FlipbookApp,代码行数:11,代码来源:test_defchararray.py


示例12: test_swapcase

 def test_swapcase(self):
     assert_(issubclass(self.A.swapcase().dtype.type, np.string_))
     assert_array_equal(self.A.swapcase(), asbytes_nested([
             [' ABC ', ''],
             ['12345', 'mIXEDcASE'],
             ['123 \t 345 \0 ', 'upper']]))
     assert_(issubclass(self.B.swapcase().dtype.type, np.unicode_))
     assert_array_equal(self.B.swapcase(), [
             [sixu(' \u03c3 '), sixu('')],
             [sixu('12345'), sixu('mIXEDcASE')],
             [sixu('123 \t 345 \0 '), sixu('upper')]])
开发者ID:MolecularFlipbook,项目名称:FlipbookApp,代码行数:11,代码来源:test_defchararray.py


示例13: test_lower

 def test_lower(self):
     assert_(issubclass(self.A.lower().dtype.type, np.string_))
     assert_array_equal(self.A.lower(), asbytes_nested([
             [' abc ', ''],
             ['12345', 'mixedcase'],
             ['123 \t 345 \0 ', 'upper']]))
     assert_(issubclass(self.B.lower().dtype.type, np.unicode_))
     assert_array_equal(self.B.lower(), [
             [sixu(' \u03c3 '), sixu('')],
             [sixu('12345'), sixu('mixedcase')],
             [sixu('123 \t 345 \0 '), sixu('upper')]])
开发者ID:MolecularFlipbook,项目名称:FlipbookApp,代码行数:11,代码来源:test_defchararray.py


示例14: test_lstrip

    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:cimarieta,项目名称:usp,代码行数:17,代码来源:test_defchararray.py


示例15: array

from __future__ import division, absolute_import, print_function

import sys

import numpy as np
from numpy.compat import asbytes, unicode, sixu
from numpy.testing import TestCase, run_module_suite, assert_equal

array(sixu(''), dtype='unicode')

# Guess the UCS length for this python interpreter
if sys.version_info[:2] >= (3, 3):
    # Python 3.3 uses a flexible string representation
    ucs4 = False

    def buffer_length(arr):
        if isinstance(arr, unicode):
            arr = str(arr)
            return (sys.getsizeof(arr+"a") - sys.getsizeof(arr)) * len(arr)
        v = memoryview(arr)
        if v.shape is None:
            return len(v) * v.itemsize
        else:
            return np.prod(v.shape) * v.itemsize
elif sys.version_info[0] >= 3:
    import array as _array

    ucs4 = (_array.array('u').itemsize == 4)

    def buffer_length(arr):
        if isinstance(arr, unicode):
开发者ID:cimarieta,项目名称:usp,代码行数:31,代码来源:test_unicode.py


示例16: test_unicode

def test_unicode():
    np.longdouble(sixu("1.2"))
开发者ID:WillieMaddox,项目名称:numpy,代码行数:2,代码来源:test_longdouble.py


示例17: test_unicode_upconvert

 def test_unicode_upconvert(self):
     A = np.char.array(['abc'])
     B = np.char.array([sixu('\u03a3')])
     assert_(issubclass((A + B).dtype.type, np.unicode_))
开发者ID:MolecularFlipbook,项目名称:FlipbookApp,代码行数:4,代码来源:test_defchararray.py


示例18: test_array_astype

def test_array_astype():
    a = np.arange(6, dtype='f4').reshape(2, 3)
    # Default behavior: allows unsafe casts, keeps memory layout,
    #                   always copies.
    b = a.astype('i4')
    assert_equal(a, b)
    assert_equal(b.dtype, np.dtype('i4'))
    assert_equal(a.strides, b.strides)
    b = a.T.astype('i4')
    assert_equal(a.T, b)
    assert_equal(b.dtype, np.dtype('i4'))
    assert_equal(a.T.strides, b.strides)
    b = a.astype('f4')
    assert_equal(a, b)
    assert_(not (a is b))

    # copy=False parameter can sometimes skip a copy
    b = a.astype('f4', copy=False)
    assert_(a is b)

    # order parameter allows overriding of the memory layout,
    # forcing a copy if the layout is wrong
    b = a.astype('f4', order='F', copy=False)
    assert_equal(a, b)
    assert_(not (a is b))
    assert_(b.flags.f_contiguous)

    b = a.astype('f4', order='C', copy=False)
    assert_equal(a, b)
    assert_(a is b)
    assert_(b.flags.c_contiguous)

    # casting parameter allows catching bad casts
    b = a.astype('c8', casting='safe')
    assert_equal(a, b)
    assert_equal(b.dtype, np.dtype('c8'))

    assert_raises(TypeError, a.astype, 'i4', casting='safe')

    # subok=False passes through a non-subclassed array
    b = a.astype('f4', subok=0, copy=False)
    assert_(a is b)

    a = np.matrix([[0, 1, 2], [3, 4, 5]], dtype='f4')

    # subok=True passes through a matrix
    b = a.astype('f4', subok=True, copy=False)
    assert_(a is b)

    # subok=True is default, and creates a subtype on a cast
    b = a.astype('i4', copy=False)
    assert_equal(a, b)
    assert_equal(type(b), np.matrix)

    # subok=False never returns a matrix
    b = a.astype('f4', subok=False, copy=False)
    assert_equal(a, b)
    assert_(not (a is b))
    assert_(type(b) is not np.matrix)

    # Make sure converting from string object to fixed length string
    # does not truncate.
    a = np.array([b'a'*100], dtype='O')
    b = a.astype('S')
    assert_equal(a, b)
    assert_equal(b.dtype, np.dtype('S100'))
    a = np.array([sixu('a')*100], dtype='O')
    b = a.astype('U')
    assert_equal(a, b)
    assert_equal(b.dtype, np.dtype('U100'))

    # Same test as above but for strings shorter than 64 characters
    a = np.array([b'a'*10], dtype='O')
    b = a.astype('S')
    assert_equal(a, b)
    assert_equal(b.dtype, np.dtype('S10'))
    a = np.array([sixu('a')*10], dtype='O')
    b = a.astype('U')
    assert_equal(a, b)
    assert_equal(b.dtype, np.dtype('U10'))

    a = np.array(123456789012345678901234567890, dtype='O').astype('S')
    assert_array_equal(a, np.array(b'1234567890' * 3, dtype='S30'))
    a = np.array(123456789012345678901234567890, dtype='O').astype('U')
    assert_array_equal(a, np.array(sixu('1234567890' * 3), dtype='U30'))

    a = np.array([123456789012345678901234567890], dtype='O').astype('S')
    assert_array_equal(a, np.array(b'1234567890' * 3, dtype='S30'))
    a = np.array([123456789012345678901234567890], dtype='O').astype('U')
    assert_array_equal(a, np.array(sixu('1234567890' * 3), dtype='U30'))

    a = np.array(123456789012345678901234567890, dtype='S')
    assert_array_equal(a, np.array(b'1234567890' * 3, dtype='S30'))
    a = np.array(123456789012345678901234567890, dtype='U')
    assert_array_equal(a, np.array(sixu('1234567890' * 3), dtype='U30'))

    a = np.array(sixu('a\u0140'), dtype='U')
    b = np.ndarray(buffer=a, dtype='uint32', shape=2)
    assert_(b.size == 2)
开发者ID:Razin-Tailor,项目名称:ChatterBot,代码行数:99,代码来源:test_api.py


示例19: test_masked_array_repr_unicode

 def test_masked_array_repr_unicode(self):
     """Ticket #1256"""
     repr(np.ma.array(sixu("Unicode")))
开发者ID:Razin-Tailor,项目名称:ChatterBot,代码行数:3,代码来源:test_regression.py


示例20: buffer_length

            return np.prod(v.shape) * v.itemsize
elif sys.version_info[0] >= 3:
    import array as _array

    ucs4 = (_array.array('u').itemsize == 4)

    def buffer_length(arr):
        if isinstance(arr, unicode):
            return _array.array('u').itemsize * len(arr)
        v = memoryview(arr)
        if v.shape is None:
            return len(v) * v.itemsize
        else:
            return np.prod(v.shape) * v.itemsize
else:
    if len(buffer(sixu('u'))) == 4:
        ucs4 = True
    else:
        ucs4 = False

    def buffer_length(arr):
        if isinstance(arr, np.ndarray):
            return len(arr.data)
        return len(buffer(arr))

# In both cases below we need to make sure that the byte swapped value (as
# UCS4) is still a valid unicode:
# Value that can be represented in UCS2 interpreters
ucs2_value = sixu('\u0900')
# Value that cannot be represented in UCS2 interpreters (but can in UCS4)
ucs4_value = sixu('\U00100900')
开发者ID:ArnoldAndersson,项目名称:numpy,代码行数:31,代码来源:test_unicode.py



注:本文中的numpy.compat.sixu函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python core.abs函数代码示例发布时间:2022-05-27
下一篇:
Python compat.open_latin1函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap