当前位置: 首页>>代码示例>>Python>>正文


Python compat.bytes方法代码示例

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


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

示例1: _decode_line

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import bytes [as 别名]
def _decode_line(line, encoding=None):
    """Decode bytes from binary input streams.

    Defaults to decoding from 'latin1'. That differs from the behavior of
    np.compat.asunicode that decodes from 'ascii'.

    Parameters
    ----------
    line : str or bytes
         Line to be decoded.

    Returns
    -------
    decoded_line : unicode
         Unicode in Python 2, a str (unicode) in Python 3.

    """
    if type(line) is bytes:
        if encoding is None:
            line = line.decode('latin1')
        else:
            line = line.decode(encoding)

    return line 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:26,代码来源:_iotools.py

示例2: _set_array_types

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import bytes [as 别名]
def _set_array_types():
    ibytes = [1, 2, 4, 8, 16, 32, 64]
    fbytes = [2, 4, 8, 10, 12, 16, 32, 64]
    for bytes in ibytes:
        bits = 8*bytes
        _add_array_type('int', bits)
        _add_array_type('uint', bits)
    for bytes in fbytes:
        bits = 8*bytes
        _add_array_type('float', bits)
        _add_array_type('complex', 2*bits)
    _gi = dtype('p')
    if _gi.type not in sctypes['int']:
        indx = 0
        sz = _gi.itemsize
        _lst = sctypes['int']
        while (indx < len(_lst) and sz >= _lst[indx](0).itemsize):
            indx += 1
        sctypes['int'].insert(indx, _gi.type)
        sctypes['uint'].insert(indx, dtype('P').type) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:22,代码来源:numerictypes.py

示例3: default_fill_value

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import bytes [as 别名]
def default_fill_value (obj):
    "Function to calculate default fill value for an object."
    if isinstance(obj, float):
        return default_real_fill_value
    elif isinstance(obj, int) or isinstance(obj, long):
        return default_integer_fill_value
    elif isinstance(obj, bytes):
        return default_character_fill_value
    elif isinstance(obj, complex):
        return default_complex_fill_value
    elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):
        x = obj.dtype.char
        if x in typecodes['Float']:
            return default_real_fill_value
        if x in typecodes['Integer']:
            return default_integer_fill_value
        if x in typecodes['Complex']:
            return default_complex_fill_value
        if x in typecodes['Character']:
            return default_character_fill_value
        if x in typecodes['UnsignedInteger']:
            return umath.absolute(default_integer_fill_value)
        return default_object_fill_value
    else:
        return default_object_fill_value 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:27,代码来源:ma.py

示例4: _is_bytes_like

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import bytes [as 别名]
def _is_bytes_like(obj):
    """
    Check whether obj behaves like a bytes object.
    """
    try:
        obj + b''
    except (TypeError, ValueError):
        return False
    return True 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,代码来源:_iotools.py

示例5: strptime

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import bytes [as 别名]
def strptime(s, fmt=None):
    """
    This function is available in the datetime module only from Python >=
    2.5.

    """
    if type(s) == bytes:
        s = s.decode("latin1")
    return datetime(*time.strptime(s, fmt)[:3]) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,代码来源:test_io.py

示例6: test_dtype_with_converters

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import bytes [as 别名]
def test_dtype_with_converters(self):
        dstr = "2009; 23; 46"
        test = np.ndfromtxt(TextIO(dstr,),
                            delimiter=";", dtype=float, converters={0: bytes})
        control = np.array([('2009', 23., 46)],
                           dtype=[('f0', '|S4'), ('f1', float), ('f2', float)])
        assert_equal(test, control)
        test = np.ndfromtxt(TextIO(dstr,),
                            delimiter=";", dtype=float, converters={0: float})
        control = np.array([2009., 23., 46],)
        assert_equal(test, control) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:13,代码来源:test_io.py

示例7: test_userconverters_with_explicit_dtype

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import bytes [as 别名]
def test_userconverters_with_explicit_dtype(self):
        # Test user_converters w/ explicit (standard) dtype
        data = TextIO('skip,skip,2001-01-01,1.0,skip')
        test = np.genfromtxt(data, delimiter=",", names=None, dtype=float,
                             usecols=(2, 3), converters={2: bytes})
        control = np.array([('2001-01-01', 1.)],
                           dtype=[('', '|S10'), ('', float)])
        assert_equal(test, control) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:test_io.py

示例8: test_recfromcsv

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import bytes [as 别名]
def test_recfromcsv(self):
        #
        data = TextIO('A,B\n0,1\n2,3')
        kwargs = dict(missing_values="N/A", names=True, case_sensitive=True)
        test = np.recfromcsv(data, dtype=None, **kwargs)
        control = np.array([(0, 1), (2, 3)],
                           dtype=[('A', int), ('B', int)])
        assert_(isinstance(test, np.recarray))
        assert_equal(test, control)
        #
        data = TextIO('A,B\n0,1\n2,N/A')
        test = np.recfromcsv(data, dtype=None, usemask=True, **kwargs)
        control = ma.array([(0, 1), (2, -1)],
                           mask=[(False, False), (False, True)],
                           dtype=[('A', int), ('B', int)])
        assert_equal(test, control)
        assert_equal(test.mask, control.mask)
        assert_equal(test.A, [0, 2])
        #
        data = TextIO('A,B\n0,1\n2,3')
        test = np.recfromcsv(data, missing_values='N/A',)
        control = np.array([(0, 1), (2, 3)],
                           dtype=[('a', int), ('b', int)])
        assert_(isinstance(test, np.recarray))
        assert_equal(test, control)
        #
        data = TextIO('A,B\n0,1\n2,3')
        dtype = [('a', int), ('b', float)]
        test = np.recfromcsv(data, missing_values='N/A', dtype=dtype)
        control = np.array([(0, 1), (2, 3)],
                           dtype=dtype)
        assert_(isinstance(test, np.recarray))
        assert_equal(test, control)

        #gh-10394
        data = TextIO('color\n"red"\n"blue"')
        test = np.recfromcsv(data, converters={0: lambda x: x.strip(b'\"')})
        control = np.array([('red',), ('blue',)], dtype=[('color', (bytes, 4))])
        assert_equal(test.dtype, control.dtype)
        assert_equal(test, control) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:42,代码来源:test_io.py

示例9: _is_bytes_like

# 需要导入模块: from numpy import compat [as 别名]
# 或者: from numpy.compat import bytes [as 别名]
def _is_bytes_like(obj):
    """
    Check whether obj behaves like a bytes object.
    """
    try:
        obj + asbytes('')
    except (TypeError, ValueError):
        return False
    return True 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:11,代码来源:_iotools.py


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