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


Python compat.asstr方法代碼示例

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


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

示例1: _read_var

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asstr [as 別名]
def _read_var(self):
        name = asstr(self._unpack_string())
        dimensions = []
        shape = []
        dims = self._unpack_int()

        for i in range(dims):
            dimid = self._unpack_int()
            dimname = self._dims[dimid]
            dimensions.append(dimname)
            dim = self.dimensions[dimname]
            shape.append(dim)
        dimensions = tuple(dimensions)
        shape = tuple(shape)

        attributes = self._read_att_array()
        nc_type = self.fp.read(4)
        vsize = self._unpack_int()
        begin = [self._unpack_int, self._unpack_int64][self.version_byte-1]()

        typecode, size = TYPEMAP[nc_type]
        dtype_ = '>%s' % typecode

        return name, dimensions, shape, attributes, typecode, size, dtype_, begin, vsize 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:26,代碼來源:netcdf.py

示例2: list_variables

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asstr [as 別名]
def list_variables(self):
        ''' list variables from stream '''
        self.mat_stream.seek(0)
        # Here we pass all the parameters in self to the reading objects
        self.initialize_read()
        self.read_file_header()
        vars = []
        while not self.end_of_stream():
            hdr, next_position = self.read_var_header()
            name = asstr(hdr.name)
            if name == '':
                # can only be a matlab 7 function workspace
                name = '__function_workspace__'

            shape = self._matrix_reader.shape_from_header(hdr)
            if hdr.is_logical:
                info = 'logical'
            else:
                info = mclass_info.get(hdr.mclass, 'unknown')
            vars.append((name, shape, info))

            self.mat_stream.seek(next_position)
        return vars 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:25,代碼來源:mio5.py

示例3: read_minimat_vars

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asstr [as 別名]
def read_minimat_vars(rdr):
    rdr.initialize_read()
    mdict = {'__globals__': []}
    i = 0
    while not rdr.end_of_stream():
        hdr, next_position = rdr.read_var_header()
        name = asstr(hdr.name)
        if name == '':
            name = 'var_%d' % i
            i += 1
        res = rdr.read_var_array(hdr, process=False)
        rdr.mat_stream.seek(next_position)
        mdict[name] = res
        if hdr.is_global:
            mdict['__globals__'].append(name)
    return mdict 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:18,代碼來源:test_mio_funcs.py

示例4: _filter_header

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asstr [as 別名]
def _filter_header(s):
    """Clean up 'L' in npz header ints.

    Cleans up the 'L' in strings representing integers. Needed to allow npz
    headers produced in Python2 to be read in Python3.

    Parameters
    ----------
    s : byte string
        Npy file header.

    Returns
    -------
    header : str
        Cleaned up header.

    """
    import tokenize
    if sys.version_info[0] >= 3:
        from io import StringIO
    else:
        from StringIO import StringIO

    tokens = []
    last_token_was_number = False
    # adding newline as python 2.7.5 workaround
    string = asstr(s) + "\n"
    for token in tokenize.generate_tokens(StringIO(string).readline):
        token_type = token[0]
        token_string = token[1]
        if (last_token_was_number and
                token_type == tokenize.NAME and
                token_string == "L"):
            continue
        else:
            tokens.append(token)
        last_token_was_number = (token_type == tokenize.NUMBER)
    # removing newline (see above) as python 2.7.5 workaround
    return tokenize.untokenize(tokens)[:-1] 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:41,代碼來源:format.py

示例5: _read_string

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asstr [as 別名]
def _read_string(f):
    '''Read a string'''
    length = _read_long(f)
    if length > 0:
        chars = _read_bytes(f, length)
        _align_32(f)
        chars = asstr(chars)
    else:
        chars = ''
    return chars 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:12,代碼來源:idl.py

示例6: _read_dim_array

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asstr [as 別名]
def _read_dim_array(self):
        header = self.fp.read(4)
        if header not in [ZERO, NC_DIMENSION]:
            raise ValueError("Unexpected header.")
        count = self._unpack_int()

        for dim in range(count):
            name = asstr(self._unpack_string())
            length = self._unpack_int() or None  # None for record dimension
            self.dimensions[name] = length
            self._dims.append(name)  # preserve order 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:13,代碼來源:netcdf.py

示例7: _read_att_array

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asstr [as 別名]
def _read_att_array(self):
        header = self.fp.read(4)
        if header not in [ZERO, NC_ATTRIBUTE]:
            raise ValueError("Unexpected header.")
        count = self._unpack_int()

        attributes = OrderedDict()
        for attr in range(count):
            name = asstr(self._unpack_string())
            attributes[name] = self._read_values()
        return attributes 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:13,代碼來源:netcdf.py

示例8: get_variables

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asstr [as 別名]
def get_variables(self, variable_names=None):
        ''' get variables from stream as dictionary

        Parameters
        ----------
        variable_names : None or str or sequence of str, optional
            variable name, or sequence of variable names to get from Mat file /
            file stream.  If None, then get all variables in file
        '''
        if isinstance(variable_names, string_types):
            variable_names = [variable_names]
        elif variable_names is not None:
            variable_names = list(variable_names)
        self.mat_stream.seek(0)
        # set up variable reader
        self.initialize_read()
        mdict = {}
        while not self.end_of_stream():
            hdr, next_position = self.read_var_header()
            name = asstr(hdr.name)
            if variable_names is not None and name not in variable_names:
                self.mat_stream.seek(next_position)
                continue
            mdict[name] = self.read_var_array(hdr)
            self.mat_stream.seek(next_position)
            if variable_names is not None:
                variable_names.remove(name)
                if len(variable_names) == 0:
                    break
        return mdict 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:32,代碼來源:mio4.py

示例9: list_variables

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asstr [as 別名]
def list_variables(self):
        ''' list variables from stream '''
        self.mat_stream.seek(0)
        # set up variable reader
        self.initialize_read()
        vars = []
        while not self.end_of_stream():
            hdr, next_position = self.read_var_header()
            name = asstr(hdr.name)
            shape = self._matrix_reader.shape_from_header(hdr)
            info = mclass_info.get(hdr.mclass, 'unknown')
            vars.append((name, shape, info))

            self.mat_stream.seek(next_position)
        return vars 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:17,代碼來源:mio4.py

示例10: _filter_header

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asstr [as 別名]
def _filter_header(s):
    """Clean up 'L' in npz header ints.

    Cleans up the 'L' in strings representing integers. Needed to allow npz
    headers produced in Python2 to be read in Python3.

    Parameters
    ----------
    s : byte string
        Npy file header.

    Returns
    -------
    header : str
        Cleaned up header.

    """
    import tokenize
    if sys.version_info[0] >= 3:
        from io import StringIO
    else:
        from StringIO import StringIO

    tokens = []
    last_token_was_number = False
    for token in tokenize.generate_tokens(StringIO(asstr(s)).read):
        token_type = token[0]
        token_string = token[1]
        if (last_token_was_number and
                token_type == tokenize.NAME and
                token_string == "L"):
            continue
        else:
            tokens.append(token)
        last_token_was_number = (token_type == tokenize.NUMBER)
    return tokenize.untokenize(tokens) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:38,代碼來源:format.py

示例11: _read_string

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asstr [as 別名]
def _read_string(f):
    '''Read a string'''
    length = _read_long(f)
    if length > 0:
        chars = _read_bytes(f, length)
        _align_32(f)
        chars = asstr(chars)
    else:
        warnings.warn("warning: empty strings are now set to '' instead of None")
        chars = ''
    return chars 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:13,代碼來源:idl.py

示例12: _read_dim_array

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asstr [as 別名]
def _read_dim_array(self):
        header = self.fp.read(4)
        if not header in [ZERO, NC_DIMENSION]:
            raise ValueError("Unexpected header.")
        count = self._unpack_int()

        for dim in range(count):
            name = asstr(self._unpack_string())
            length = self._unpack_int() or None  # None for record dimension
            self.dimensions[name] = length
            self._dims.append(name)  # preserve order 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:13,代碼來源:netcdf.py

示例13: _read_att_array

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asstr [as 別名]
def _read_att_array(self):
        header = self.fp.read(4)
        if not header in [ZERO, NC_ATTRIBUTE]:
            raise ValueError("Unexpected header.")
        count = self._unpack_int()

        attributes = {}
        for attr in range(count):
            name = asstr(self._unpack_string())
            attributes[name] = self._read_values()
        return attributes 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:13,代碼來源:netcdf.py

示例14: get_variables

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asstr [as 別名]
def get_variables(self, variable_names=None):
        ''' get variables from stream as dictionary

        Parameters
        ----------
        variable_names : None or str or sequence of str, optional
            variable name, or sequence of variable names to get from Mat file /
            file stream.  If None, then get all variables in file
        '''
        if isinstance(variable_names, string_types):
            variable_names = [variable_names]
        elif variable_names is not None:
            variable_names = list(variable_names)
        self.mat_stream.seek(0)
        # set up variable reader
        self.initialize_read()
        mdict = {}
        while not self.end_of_stream():
            hdr, next_position = self.read_var_header()
            name = asstr(hdr.name)
            if variable_names and name not in variable_names:
                self.mat_stream.seek(next_position)
                continue
            mdict[name] = self.read_var_array(hdr)
            self.mat_stream.seek(next_position)
            if variable_names:
                variable_names.remove(name)
                if len(variable_names) == 0:
                    break
        return mdict 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:32,代碼來源:mio4.py

示例15: _read_att_array

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import asstr [as 別名]
def _read_att_array(self):
        header = self.fp.read(4)
        if header not in [ZERO, NC_ATTRIBUTE]:
            raise ValueError("Unexpected header.")
        count = self._unpack_int()

        attributes = OrderedDict()
        for attr in range(count):
            name = asstr(self._unpack_string())
            attributes[name] = self._read_att_values()
        return attributes 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:13,代碼來源:netcdf.py


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