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


Python numpy.bytes_函数代码示例

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


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

示例1: _convert_to_numpy_bytes

def _convert_to_numpy_bytes(s):
    if isinstance(s, np.bytes_):
        return s
    elif isinstance(s, bytes):
        return np.bytes_(s)
    else:
        return np.bytes_(s.encode())
开发者ID:frejanordsiek,项目名称:Acquisition_HDF5,代码行数:7,代码来源:Acquisition_HDF5.py

示例2: getAttr

def getAttr( dataset, ky ):
  try:
    attrib = dataset.attrs[ky]
    return np.bytes_(dataset.attrs[ky]).decode().rstrip().split("\x00")[0]
  except KeyError:
    print( "HDF5 key not found: '"+ky+"'. Available keys:\n")
    print( list(dataset.attrs.keys()) )
    raise
开发者ID:OpendTect,项目名称:OpendTect,代码行数:8,代码来源:hdf5.py

示例3: setUp

    def setUp(self):
        pass
        self.b_lit = b'bytes literal'
        self.s_lit = 'literal literal'
        self.u_lit = u'unicode literal'

        self.np_b_lit = np.bytes_('numpy bytes literal')
        self.np_s_lit = np.str_('numpy unicode literal')
        self.np_u_lit = np.unicode_('numpy unicode literal')
开发者ID:titusjan,项目名称:argos,代码行数:9,代码来源:test_utils.py

示例4: test_isscalar_numpy_array_scalars

 def test_isscalar_numpy_array_scalars(self):
     self.assertTrue(lib.isscalar(np.int64(1)))
     self.assertTrue(lib.isscalar(np.float64(1.0)))
     self.assertTrue(lib.isscalar(np.int32(1)))
     self.assertTrue(lib.isscalar(np.object_("foobar")))
     self.assertTrue(lib.isscalar(np.str_("foobar")))
     self.assertTrue(lib.isscalar(np.unicode_(u("foobar"))))
     self.assertTrue(lib.isscalar(np.bytes_(b"foobar")))
     self.assertTrue(lib.isscalar(np.datetime64("2014-01-01")))
     self.assertTrue(lib.isscalar(np.timedelta64(1, "h")))
开发者ID:Feyi1,项目名称:pandas,代码行数:10,代码来源:test_infer_and_convert.py

示例5: test_isscalar_numpy_array_scalars

 def test_isscalar_numpy_array_scalars(self):
     self.assertTrue(is_scalar(np.int64(1)))
     self.assertTrue(is_scalar(np.float64(1.)))
     self.assertTrue(is_scalar(np.int32(1)))
     self.assertTrue(is_scalar(np.object_('foobar')))
     self.assertTrue(is_scalar(np.str_('foobar')))
     self.assertTrue(is_scalar(np.unicode_(u('foobar'))))
     self.assertTrue(is_scalar(np.bytes_(b'foobar')))
     self.assertTrue(is_scalar(np.datetime64('2014-01-01')))
     self.assertTrue(is_scalar(np.timedelta64(1, 'h')))
开发者ID:cgrin,项目名称:pandas,代码行数:10,代码来源:test_inference.py

示例6: random_numpy

def random_numpy(shape, dtype, allow_nan=True,
                 allow_unicode=False):
    # Makes a random numpy array of the specified shape and dtype
    # string. The method is slightly different depending on the
    # type. For 'bytes', 'str', and 'object'; an array of the
    # specified size is made and then each element is set to either
    # a numpy.bytes_, numpy.str_, or some other object of any type
    # (here, it is a randomly typed random numpy array). If it is
    # any other type, then it is just a matter of constructing the
    # right sized ndarray from a random sequence of bytes (all must
    # be forced to 0 and 1 for bool). Optionally include unicode
    # characters.
    if dtype == 'S':
        length = random.randint(1, max_string_length)
        data = np.zeros(shape=shape, dtype='S' + str(length))
        for x in np.nditer(data, op_flags=['readwrite']):
            if allow_unicode:
                chars = random_bytes_fullrange(length)
            else:
                chars = random_bytes(length)
            x[...] = np.bytes_(chars)
        return data
    elif dtype == 'U':
        length = random.randint(1, max_string_length)
        data = np.zeros(shape=shape, dtype='U' + str(length))
        for x in np.nditer(data, op_flags=['readwrite']):
            if allow_unicode:
                chars = _random_str_some_unicode(length)
            else:
                chars = random_str_ascii(length)
            x[...] = np.unicode_(chars)
        return data
    elif dtype == 'object':
        data = np.zeros(shape=shape, dtype='object')
        for index, x in np.ndenumerate(data):
            data[index] = random_numpy( \
                shape=random_numpy_shape( \
                object_subarray_dimensions, \
                max_object_subarray_axis_length), \
                dtype=random.choice(dtypes))
        return data
    else:
        nbytes = np.ndarray(shape=(1,), dtype=dtype).nbytes
        bts = np.random.bytes(nbytes * np.prod(shape))
        if dtype == 'bool':
            bts = b''.join([{True: b'\x01', False: b'\x00'}[ \
                ch > 127] for ch in bts])
        data = np.ndarray(shape=shape, dtype=dtype, buffer=bts)
        # If it is a floating point type and we are supposed to
        # remove NaN's, then turn them to zeros.
        if not allow_nan and data.dtype.kind in ('f', 'c') \
            and np.any(np.isnan(data)):
            data = data.copy()
            data[np.isnan(data)] = 0.0
        return data
开发者ID:dashesy,项目名称:hdf5storage,代码行数:55,代码来源:make_randoms.py

示例7: logfile

 def logfile(self, logfile):
     if PYVERSION == 3:
         try:
             self.radex.setup.logfile[:] = np.bytes_([""]*len(self.radex.setup.logfile))
         except TypeError as ex:
             self.radex.setup.logfile = " " * self.radex.setup.logfile.dtype.itemsize
     else:
         self.radex.setup.logfile[:] = ""
     try:
         self.radex.setup.logfile[:len(logfile)] = logfile
     except IndexError:
         self.radex.setup.logfile = logfile + " " * (self.radex.setup.logfile.dtype.itemsize - len(logfile))
开发者ID:keflavich,项目名称:pyradex,代码行数:12,代码来源:core.py

示例8: outfile

 def outfile(self, outfile):
     if PYVERSION == 3:
         try:
             self.radex.impex.outfile[:] = np.bytes_([""]*len(self.radex.impex.outfile))
         except TypeError as ex:
             self.radex.impex.outfile = " " * self.radex.impex.outfile.dtype.itemsize
     else:
         self.radex.impex.outfile[:] = ""
     try:
         self.radex.impex.outfile[:len(outfile)] = outfile
     except IndexError:
         self.radex.impex.outfile = outfile + " " * (self.radex.impex.outfile.dtype.itemsize - len(outfile))
开发者ID:keflavich,项目名称:pyradex,代码行数:12,代码来源:core.py

示例9: search_for_string

def search_for_string(h5_str, value):
    match = False
    if h5_str is not None:
        if isinstance(h5_str, (str, np.string_)):
            if h5_str == value:
                match = True
        elif isinstance(h5_str, (list, np.ndarray)):
            match = False
            for i in range(len(h5_str)):
                if h5_str[i] == value or h5_str[i] == np.bytes_(value):
                    match = True
                    break
    return match
开发者ID:deep-introspection,项目名称:nwb-api,代码行数:13,代码来源:test_utils.py

示例10: random_numpy_scalar

def random_numpy_scalar(dtype):
    # How a random scalar is made depends on th type. For must, it
    # is just a single number. But for the string types, it is a
    # string of any length.
    if dtype == 'S':
        return np.bytes_(random_bytes(random.randint(1,
                         max_string_length)))
    elif dtype == 'U':
        return np.unicode_(random_str_ascii(
                           random.randint(1,
                           max_string_length)))
    else:
        return random_numpy(tuple(), dtype)[()]
开发者ID:dashesy,项目名称:hdf5storage,代码行数:13,代码来源:make_randoms.py

示例11: check_shaderError

def check_shaderError(shader, flag, isProgram, errorMessage):
    success = bgl.Buffer(bgl.GL_INT, 1)

    if isProgram:
        bgl.glGetProgramiv(shader, flag, success)
    else:
        bgl.glGetShaderiv(shader, flag, success)

    if success[0] == bgl.GL_FALSE:
        import numpy as np
        import ctypes

        offset = bgl.Buffer(bgl.GL_INT, 1, (ctypes.c_int32 * 1).from_address(0))
        error = bgl.Buffer(bgl.GL_BYTE, 1024)
        if isProgram:
            bgl.glGetProgramInfoLog(shader, 1024, offset, error)
            print(errorMessage, np.bytes_(error).decode("utf-8"))
        else:
            bgl.glGetShaderInfoLog(shader, 1024, offset, error)
            print(errorMessage, np.bytes_(error).decode("utf-8"))

        del offset
        raise #RuntimeError(errorMessage, bgl.glGetShaderInfoLog(shader))
开发者ID:mgschwan,项目名称:blensor,代码行数:23,代码来源:utils_shader.py

示例12: molpath

 def molpath(self, molfile):
     if "~" in molfile:
         molfile = os.path.expanduser(molfile)
     if PYVERSION == 3:
         try:
             self.radex.impex.molfile[:] = np.bytes_([""]*len(self.radex.impex.molfile))
         except TypeError as ex:
             self.radex.impex.molfile = " " * self.radex.impex.molfile.dtype.itemsize
     else:
         self.radex.impex.molfile[:] = ""
     utils.verify_collisionratefile(molfile)
     try:
         self.radex.impex.molfile[:len(molfile)] = molfile
     except IndexError:
         self.radex.impex.molfile = molfile + " " * (self.radex.impex.molfile.dtype.itemsize - len(molfile))
开发者ID:keflavich,项目名称:pyradex,代码行数:15,代码来源:core.py

示例13: set_attribute_string

def set_attribute_string(target, name, value):
    """ Sets an attribute to a string on a Dataset or Group.

    If the attribute `name` doesn't exist yet, it is created. If it
    already exists, it is overwritten if it differs from `value`.

    Parameters
    ----------
    target : Dataset or Group
        Dataset or Group to set the string attribute of.
    name : str
        Name of the attribute to set.
    value : string
        Value to set the attribute to. Can be any sort of string type
        that will convert to a ``numpy.bytes_``

    """
    set_attribute(target, name, np.bytes_(value))
开发者ID:dashesy,项目名称:hdf5storage,代码行数:18,代码来源:utilities.py

示例14: datapath

 def datapath(self, radat):
     # self.radex data path not needed if molecule given as full path
     if PYVERSION == 3:
         try:
             self.radex.setup.radat[:] = np.bytes_([""] * len(self.radex.setup.radat))
         except TypeError as ex:
             # now radat gets treated as a single S120 instead of an array of S1s
             self.radex.setup.radat = " " * self.radex.setup.radat.dtype.itemsize
     else:
         self.radex.setup.radat[:] = ""
     # there is dangerous magic here: radat needs to be interpreted as an array,
     # but you can't make it an array of characters easily...
     try:
         self.radex.setup.radat[:len(radat)] = radat
     except IndexError:
         # in python3, this might just work, where the above doesn't?
         # (this works if RADAT is an S120)
         # the added space is because the right and left side must have *exactly* the same size
         self.radex.setup.radat = radat + " " * (self.radex.setup.radat.dtype.itemsize - len(radat))
开发者ID:keflavich,项目名称:pyradex,代码行数:19,代码来源:core.py

示例15: check_dict_like_other_type_key

    def check_dict_like_other_type_key(self, tp, other_tp):
        data = random_dict(tp)

        key_gen = random_str_some_unicode(max_dict_key_length)
        if other_tp == 'numpy.bytes_':
            key = np.bytes_(key_gen.encode('UTF-8'))
        elif other_tp == 'numpy.unicode_':
            key = np.unicode_(key_gen)
        elif other_tp == 'bytes':
            key = key_gen.encode('UTF-8')
        elif other_tp == 'int':
            key = random_int()
        elif other_tp == 'float':
            key = random_float()

        data[key] = random_int()
        out = self.write_readback(data, random_name(),
                                  self.options)
        self.assert_equal(out, data)
开发者ID:frejanordsiek,项目名称:hdf5storage,代码行数:19,代码来源:test_write_readback.py


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