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


Python numpy.string方法代碼示例

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


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

示例1: get_bases

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import string [as 別名]
def get_bases(self):
        "get bases from SpaceGroup element"
        # lattice parameters
        bases = []
        for elem in self.tree.iter():
            if elem.tag == 'SpaceGroup':
                for attr in ['AVector', 'BVector', 'CVector']:
                    basis = elem.attrib[attr]  # string
                    basis = [float(i.strip()) for i in basis.split(',')]
                    bases.append(basis)
                break
        bases = np.array(bases)
        #set base constant as 1.0
        self.bases_const = 1.0

        return bases 
開發者ID:PytLab,項目名稱:VASPy,代碼行數:18,代碼來源:matstudio.py

示例2: __init__

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import string [as 別名]
def __init__(self, filename):
        """
        Create a Material Studio *.arc file class.

        Example:

        >>> a = ArcFile("00-05.arc")

        Class attributes descriptions
        ================================================================
         Attribute         Description
         ===============  ==============================================
         filename          string, name of arc file.
         coords_iterator   generator, yield Cartisan coordinates in
                           numpy array.
         lengths           list of float, lengths of lattice axes.
         angles            list of float, angles of lattice axes.
        ================  ==============================================
        """
        super(ArcFile, self).__init__(filename)

        # Set logger.
        self.__logger = logging.getLogger("vaspy.ArcFile") 
開發者ID:PytLab,項目名稱:VASPy,代碼行數:25,代碼來源:matstudio.py

示例3: __init__

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import string [as 別名]
def __init__(self, filename='XDATCAR'):
        """
        Class to generate XDATCAR objects.

        Example:

        >>> a = XdatCar()

        Class attributes descriptions
        =======================================================================
          Attribute      Description
          ============  =======================================================
          filename       string, name of the file the direct coordiante data
                         stored in
          bases_const    float, lattice bases constant
          bases          np.array, bases of POSCAR
          natom          int, the number of total atom number
          atom_types     list of strings, atom types
          tf             list of list, T&F info of atoms
          info_nline     int, line numbers of lattice info
          ============  =======================================================
        """
        AtomCo.__init__(self, filename)
        self.info_nline = 7  # line numbers of lattice info
        self.load() 
開發者ID:PytLab,項目名稱:VASPy,代碼行數:27,代碼來源:atomco.py

示例4: validate_col

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import string [as 別名]
def validate_col(self, itemsize=None):
        """ validate this column: return the compared against itemsize """

        # validate this column for string truncation (or reset to the max size)
        if _ensure_decoded(self.kind) == u'string':
            c = self.col
            if c is not None:
                if itemsize is None:
                    itemsize = self.itemsize
                if c.itemsize < itemsize:
                    raise ValueError(
                        "Trying to store a string with len [{itemsize}] in "
                        "[{cname}] column but\nthis column has a limit of "
                        "[{c_itemsize}]!\nConsider using min_itemsize to "
                        "preset the sizes on these columns".format(
                            itemsize=itemsize, cname=self.cname,
                            c_itemsize=c.itemsize))
                return c.itemsize

        return None 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:22,代碼來源:pytables.py

示例5: generate

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import string [as 別名]
def generate(self, where):
        """ where can be a : dict,list,tuple,string """
        if where is None:
            return None

        q = self.table.queryables()
        try:
            return Expr(where, queryables=q, encoding=self.table.encoding)
        except NameError:
            # raise a nice message, suggesting that the user should use
            # data_columns
            raise ValueError(
                "The passed where expression: {0}\n"
                "            contains an invalid variable reference\n"
                "            all of the variable references must be a "
                "reference to\n"
                "            an axis (e.g. 'index' or 'columns'), or a "
                "data_column\n"
                "            The currently defined references are: {1}\n"
                .format(where, ','.join(q.keys()))
            ) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:23,代碼來源:pytables.py

示例6: min

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import string [as 別名]
def min(self):
    """Returns the minimum representable value in this data type.

    Raises:
      TypeError: if this is a non-numeric, unordered, or quantized type.

    """
    if (self.is_quantized or self.base_dtype in
        (bool, string, complex64, complex128)):
      raise TypeError("Cannot find minimum value of %s." % self)

    # there is no simple way to get the min value of a dtype, we have to check
    # float and int types separately
    try:
      return np.finfo(self.as_numpy_dtype()).min
    except:  # bare except as possible raises by finfo not documented
      try:
        return np.iinfo(self.as_numpy_dtype()).min
      except:
        raise TypeError("Cannot find minimum value of %s." % self) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:22,代碼來源:dtypes.py

示例7: max

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import string [as 別名]
def max(self):
    """Returns the maximum representable value in this data type.

    Raises:
      TypeError: if this is a non-numeric, unordered, or quantized type.

    """
    if (self.is_quantized or self.base_dtype in
        (bool, string, complex64, complex128)):
      raise TypeError("Cannot find maximum value of %s." % self)

    # there is no simple way to get the max value of a dtype, we have to check
    # float and int types separately
    try:
      return np.finfo(self.as_numpy_dtype()).max
    except:  # bare except as possible raises by finfo not documented
      try:
        return np.iinfo(self.as_numpy_dtype()).max
      except:
        raise TypeError("Cannot find maximum value of %s." % self) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:22,代碼來源:dtypes.py

示例8: validate_col

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import string [as 別名]
def validate_col(self, itemsize=None):
        """ validate this column: return the compared against itemsize """

        # validate this column for string truncation (or reset to the max size)
        if _ensure_decoded(self.kind) == u('string'):
            c = self.col
            if c is not None:
                if itemsize is None:
                    itemsize = self.itemsize
                if c.itemsize < itemsize:
                    raise ValueError(
                        "Trying to store a string with len [%s] in [%s] "
                        "column but\nthis column has a limit of [%s]!\n"
                        "Consider using min_itemsize to preset the sizes on "
                        "these columns" % (itemsize, self.cname, c.itemsize))
                return c.itemsize

        return None 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:20,代碼來源:pytables.py

示例9: min

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import string [as 別名]
def min(self):
        """Returns the minimum representable value in this data type.

        Raises:
          TypeError: if this is a non-numeric, unordered, or quantized type.
        """
        if self.is_quantized or self.base_dtype in (
            bool,
            string,
            complex64,
            complex128,
        ):
            raise TypeError("Cannot find minimum value of %s." % self)

        # there is no simple way to get the min value of a dtype, we have to check
        # float and int types separately
        try:
            return np.finfo(self.as_numpy_dtype).min
        except:  # bare except as possible raises by finfo not documented
            try:
                return np.iinfo(self.as_numpy_dtype).min
            except:
                if self.base_dtype == bfloat16:
                    return _np_bfloat16(float.fromhex("-0x1.FEp127"))
                raise TypeError("Cannot find minimum value of %s." % self) 
開發者ID:tensorflow,項目名稱:tensorboard,代碼行數:27,代碼來源:dtypes.py

示例10: max

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import string [as 別名]
def max(self):
        """Returns the maximum representable value in this data type.

        Raises:
          TypeError: if this is a non-numeric, unordered, or quantized type.
        """
        if self.is_quantized or self.base_dtype in (
            bool,
            string,
            complex64,
            complex128,
        ):
            raise TypeError("Cannot find maximum value of %s." % self)

        # there is no simple way to get the max value of a dtype, we have to check
        # float and int types separately
        try:
            return np.finfo(self.as_numpy_dtype).max
        except:  # bare except as possible raises by finfo not documented
            try:
                return np.iinfo(self.as_numpy_dtype).max
            except:
                if self.base_dtype == bfloat16:
                    return _np_bfloat16(float.fromhex("0x1.FEp127"))
                raise TypeError("Cannot find maximum value of %s." % self) 
開發者ID:tensorflow,項目名稱:tensorboard,代碼行數:27,代碼來源:dtypes.py

示例11: get_name_info

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import string [as 別名]
def get_name_info(self):
        """
        獲取文件中能量,力等數據.
        """
        # Get info string.
        info = None
        for elem in self.tree.iter("SymmetrySystem"):
            info = elem.attrib.get('Name')
            break
        if info is None:
            return

        # Get thermo data.
        fieldnames = ["energy", "force", "magnetism", "path"]
        try:
            for key, value in zip(fieldnames, info.split()):
                if key != "path":
                    data = float(value.split(':')[-1].strip())
                else:
                    data = value.split(":")[-1].strip()
                setattr(self, key, data)
        except:
            # Set default values.
            self.force, self.energy, self.magnetism = 0.0, 0.0, 0.0

            msg = "No data info in Name property '{}'".format(info)
            self.__logger.warning(msg)
        finally:
            self.path = getcwd() 
開發者ID:PytLab,項目名稱:VASPy,代碼行數:31,代碼來源:matstudio.py

示例12: update_bases

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import string [as 別名]
def update_bases(self):
        "update bases value in ElementTree"
        bases = self.bases.tolist()
        bases_str = []
        # float -> string
        for basis in bases:
            xyz = ','.join([str(v) for v in basis])  # vector string
            bases_str.append(xyz)
        for elem in self.tree.iter('SpaceGroup'):
            elem.set('AVector', bases_str[0])
            elem.set('BVector', bases_str[1])
            elem.set('CVector', bases_str[2])
            break 
開發者ID:PytLab,項目名稱:VASPy,代碼行數:15,代碼來源:matstudio.py

示例13: load

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import string [as 別名]
def load(self, content_list):
        """ Load all data in xyz file.
        """
        # Total number of all atoms.
        natom = int(content_list[0].strip())

        # The iteration step for this xyz file.
        step = int(str2list(content_list[1])[-1])

        # Get atom coordinate and number info
        data_list = [str2list(line) for line in content_list[2:]]
        data_array = np.array(data_list)      # dtype=np.string
        atoms_list = list(data_array[:, 0])   # 1st column
        data = np.float64(data_array[:, 1:])  # rest columns

        # Atom number for each atom
        atom_types = []
        for atom in atoms_list:
            if atom not in atom_types:
                atom_types.append(atom)
        atom_numbers = [atoms_list.count(atom) for atom in atom_types]

        # Set attributes.
        self.natom = natom
        self.step = step
        self.atom_types = atom_types
        self.atom_numbers = atom_numbers
        self.data = data 
開發者ID:PytLab,項目名稱:VASPy,代碼行數:30,代碼來源:atomco.py

示例14: _ensure_str

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import string [as 別名]
def _ensure_str(name):
    """Ensure that an index / column name is a str (python 3) or
    unicode (python 2); otherwise they may be np.string dtype.
    Non-string dtypes are passed through unchanged.

    https://github.com/pandas-dev/pandas/issues/13492
    """
    if isinstance(name, compat.string_types):
        name = compat.text_type(name)
    return name 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:12,代碼來源:pytables.py

示例15: maybe_set_size

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import string [as 別名]
def maybe_set_size(self, min_itemsize=None):
        """ maybe set a string col itemsize:
               min_itemsize can be an integer or a dict with this columns name
               with an integer size """
        if _ensure_decoded(self.kind) == u'string':

            if isinstance(min_itemsize, dict):
                min_itemsize = min_itemsize.get(self.name)

            if min_itemsize is not None and self.typ.itemsize < min_itemsize:
                self.typ = _tables(
                ).StringCol(itemsize=min_itemsize, pos=self.pos) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:14,代碼來源:pytables.py


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