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


Python numpy.string_方法代码示例

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


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

示例1: nan_filter

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import string_ [as 别名]
def nan_filter(self):
        """Populates Target List and filters out values which are nan
        
        """
        
        # filter out nan values in numerical attributes
        for att in self.catalog_atts:
            if ('close' in att) or ('bright' in att):
                continue
            if getattr(self, att).shape[0] == 0:
                pass
            elif (type(getattr(self, att)[0]) == str) or (type(getattr(self, att)[0]) == bytes):
                # FIXME: intent here unclear: 
                #   note float('nan') is an IEEE NaN, getattr(.) is a str, and != on NaNs is special
                i = np.where(getattr(self, att) != float('nan'))[0]
                self.revise_lists(i)
            # exclude non-numerical types
            elif type(getattr(self, att)[0]) not in (np.unicode_, np.string_, np.bool_, bytes):
                if att == 'coords':
                    i1 = np.where(~np.isnan(self.coords.ra.to('deg').value))[0]
                    i2 = np.where(~np.isnan(self.coords.dec.to('deg').value))[0]
                    i = np.intersect1d(i1,i2)
                else:
                    i = np.where(~np.isnan(getattr(self, att)))[0]
                self.revise_lists(i) 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:27,代码来源:TargetList.py

示例2: fen2state

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import string_ [as 别名]
def fen2state(fen):
    '''
    transfer the fen string to chessboard
    fen: fen string
    return: state of the chessboard
    '''
    fenstrlist = fen.split()
    cstate = chessboradstate()
    cstate.state = np.zeros([10, 9], np.string_)
    fenstr1st = fenstrlist[0].split('/')
    for i in range(len(fenstr1st)):
        current = 0
        for j in range(len(fenstr1st[i])):
            if fenstr1st[i][j].isdigit():
                num = int(fenstr1st[i][j])
                for k in range(num):
                    cstate.state[i][current+k] = ' '
                current += num
            else:
                cstate.state[i][current] = fenstr1st[i][j]
                current += 1
    cstate.turn = fenstrlist[1]
    cstate.roundcnt = int(fenstrlist[5])
    return cstate 
开发者ID:milkpku,项目名称:BetaElephant,代码行数:26,代码来源:datatransfer.py

示例3: move

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import string_ [as 别名]
def move(cstate, move):
    '''
    move the chess according to the move action
    state: the current chessborad, numpy.array[10][9], dtype=string_
    move: the action to move, string format as:'D5-E5'
    '''
    src = []
    des = []
    src.append(9 - int(move[1]))
    src.append(ord(move[0]) - ord('A'))
    des.append(9 - int(move[4]))
    des.append(ord(move[3]) - ord('A'))
    # print src, des
    chess = cstate.state[src[0]][src[1]]
    cstate.state[src[0]][src[1]] = ' '
    cstate.state[des[0]][des[1]] = chess
    cstate.roundcnt += 1
    if cstate.turn == 'b':
        cstate.turn = 'w'
    else:
        cstate.turn = 'b' 
开发者ID:milkpku,项目名称:BetaElephant,代码行数:23,代码来源:datatransfer.py

示例4: test_char_radd

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import string_ [as 别名]
def test_char_radd(self):
        # GH issue 9620, reached gentype_add and raise TypeError
        np_s = np.string_('abc')
        np_u = np.unicode_('abc')
        s = b'def'
        u = u'def'
        assert_(np_s.__radd__(np_s) is NotImplemented)
        assert_(np_s.__radd__(np_u) is NotImplemented)
        assert_(np_s.__radd__(s) is NotImplemented)
        assert_(np_s.__radd__(u) is NotImplemented)
        assert_(np_u.__radd__(np_s) is NotImplemented)
        assert_(np_u.__radd__(np_u) is NotImplemented)
        assert_(np_u.__radd__(s) is NotImplemented)
        assert_(np_u.__radd__(u) is NotImplemented)
        assert_(s + np_s == b'defabc')
        assert_(u + np_u == u'defabc')


        class Mystr(str, np.generic):
            # would segfault
            pass

        ret = s + Mystr('abc')
        assert_(type(ret) is type(s)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:26,代码来源:test_scalarinherit.py

示例5: test_from_string_array

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import string_ [as 别名]
def test_from_string_array(self):
        A = np.array([[b'abc', b'foo'],
                      [b'long   ', b'0123456789']])
        assert_equal(A.dtype.type, np.string_)
        B = np.char.array(A)
        assert_array_equal(B, A)
        assert_equal(B.dtype, A.dtype)
        assert_equal(B.shape, A.shape)
        B[0, 0] = 'changed'
        assert_(B[0, 0] != A[0, 0])
        C = np.char.asarray(A)
        assert_array_equal(C, A)
        assert_equal(C.dtype, A.dtype)
        C[0, 0] = 'changed again'
        assert_(C[0, 0] != B[0, 0])
        assert_(C[0, 0] == A[0, 0]) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:test_defchararray.py

示例6: test_join

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import string_ [as 别名]
def test_join(self):
        if sys.version_info[0] >= 3:
            # NOTE: list(b'123') == [49, 50, 51]
            #       so that b','.join(b'123') results to an error on Py3
            A0 = self.A.decode('ascii')
        else:
            A0 = self.A

        A = np.char.join([',', '#'], A0)
        if sys.version_info[0] >= 3:
            assert_(issubclass(A.dtype.type, np.unicode_))
        else:
            assert_(issubclass(A.dtype.type, np.string_))
        tgt = np.array([[' ,a,b,c, ', ''],
                        ['1,2,3,4,5', 'M#i#x#e#d#C#a#s#e'],
                        ['1,2,3, ,\t, ,3,4,5, ,\x00, ', 'U#P#P#E#R']])
        assert_array_equal(np.char.join([',', '#'], A0), tgt) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:19,代码来源:test_defchararray.py

示例7: test_ljust

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import string_ [as 别名]
def test_ljust(self):
        assert_(issubclass(self.A.ljust(10).dtype.type, np.string_))

        C = self.A.ljust([10, 20])
        assert_array_equal(np.char.str_len(C), [[10, 20], [10, 20], [12, 20]])

        C = self.A.ljust(20, b'#')
        assert_array_equal(C.startswith(b'#'), [
                [False, True], [False, False], [False, False]])
        assert_(np.all(C.endswith(b'#')))

        C = np.char.ljust(b'FOO', [[10, 20], [15, 8]])
        tgt = [[b'FOO       ', b'FOO                 '],
               [b'FOO            ', b'FOO     ']]
        assert_(issubclass(C.dtype.type, np.string_))
        assert_array_equal(C, tgt) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:test_defchararray.py

示例8: test_lstrip

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import string_ [as 别名]
def test_lstrip(self):
        tgt = [[b'abc ', b''],
               [b'12345', b'MixedCase'],
               [b'123 \t 345 \0 ', b'UPPER']]
        assert_(issubclass(self.A.lstrip().dtype.type, np.string_))
        assert_array_equal(self.A.lstrip(), tgt)

        tgt = [[b' abc', b''],
               [b'2345', b'ixedCase'],
               [b'23 \t 345 \x00', b'UPPER']]
        assert_array_equal(self.A.lstrip([b'1', b'M']), tgt)

        tgt = [[u'\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:Frank-qlu,项目名称:recruit,代码行数:19,代码来源:test_defchararray.py

示例9: test_rjust

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import string_ [as 别名]
def test_rjust(self):
        assert_(issubclass(self.A.rjust(10).dtype.type, np.string_))

        C = self.A.rjust([10, 20])
        assert_array_equal(np.char.str_len(C), [[10, 20], [10, 20], [12, 20]])

        C = self.A.rjust(20, b'#')
        assert_(np.all(C.startswith(b'#')))
        assert_array_equal(C.endswith(b'#'),
                           [[False, True], [False, False], [False, False]])

        C = np.char.rjust(b'FOO', [[10, 20], [15, 8]])
        tgt = [[b'       FOO', b'                 FOO'],
               [b'            FOO', b'     FOO']]
        assert_(issubclass(C.dtype.type, np.string_))
        assert_array_equal(C, tgt) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:test_defchararray.py

示例10: test_rstrip

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import string_ [as 别名]
def test_rstrip(self):
        assert_(issubclass(self.A.rstrip().dtype.type, np.string_))

        tgt = [[b' abc', b''],
               [b'12345', b'MixedCase'],
               [b'123 \t 345', b'UPPER']]
        assert_array_equal(self.A.rstrip(), tgt)

        tgt = [[b' abc ', b''],
               [b'1234', b'MixedCase'],
               [b'123 \t 345 \x00', b'UPP']
               ]
        assert_array_equal(self.A.rstrip([b'5', b'ER']), tgt)

        tgt = [[u' \u03a3', ''],
               ['12345', 'MixedCase'],
               ['123 \t 345', 'UPPER']]
        assert_(issubclass(self.B.rstrip().dtype.type, np.unicode_))
        assert_array_equal(self.B.rstrip(), tgt) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:21,代码来源:test_defchararray.py

示例11: test_strip

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import string_ [as 别名]
def test_strip(self):
        tgt = [[b'abc', b''],
               [b'12345', b'MixedCase'],
               [b'123 \t 345', b'UPPER']]
        assert_(issubclass(self.A.strip().dtype.type, np.string_))
        assert_array_equal(self.A.strip(), tgt)

        tgt = [[b' abc ', b''],
               [b'234', b'ixedCas'],
               [b'23 \t 345 \x00', b'UPP']]
        assert_array_equal(self.A.strip([b'15', b'EReM']), tgt)

        tgt = [[u'\u03a3', ''],
               ['12345', 'MixedCase'],
               ['123 \t 345', 'UPPER']]
        assert_(issubclass(self.B.strip().dtype.type, np.unicode_))
        assert_array_equal(self.B.strip(), tgt) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:19,代码来源:test_defchararray.py

示例12: add

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import string_ [as 别名]
def add(x1, x2):
    """
    Return element-wise string concatenation for two arrays of str or unicode.

    Arrays `x1` and `x2` must have the same shape.

    Parameters
    ----------
    x1 : array_like of str or unicode
        Input array.
    x2 : array_like of str or unicode
        Input array.

    Returns
    -------
    add : ndarray
        Output array of `string_` or `unicode_`, depending on input types
        of the same shape as `x1` and `x2`.

    """
    arr1 = numpy.asarray(x1)
    arr2 = numpy.asarray(x2)
    out_size = _get_num_chars(arr1) + _get_num_chars(arr2)
    dtype = _use_unicode(arr1, arr2)
    return _vec_string(arr1, (dtype, out_size), '__add__', (arr2,)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:27,代码来源:defchararray.py

示例13: label_axes

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import string_ [as 别名]
def label_axes(h5object, labels, units=None):
    '''Stamp the given HDF5 object with axis labels. This stores the axis labels
    in an array of strings in an attribute called ``axis_labels`` on the given
    object. ``units`` if provided is a corresponding list of units.'''
    
    if len(labels) != len(h5object.shape):
        raise ValueError('number of axes and number of labels do not match')
    
    if units is None: units = []
    
    if len(units) and len(units) != len(labels):
        raise ValueError('number of units labels does not match number of axes')
    
    h5object.attrs['axis_labels'] = numpy.array([numpy.string_(i) for i in labels])
     
    if len(units):
        h5object.attrs['axis_units'] = numpy.array([numpy.string_(i) for i in units]) 
开发者ID:westpa,项目名称:westpa,代码行数:19,代码来源:h5io.py

示例14: test_from_string_array

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import string_ [as 别名]
def test_from_string_array(self):
        A = np.array(asbytes_nested([['abc', 'foo'],
                                     ['long   ', '0123456789']]))
        assert_equal(A.dtype.type, np.string_)
        B = np.char.array(A)
        assert_array_equal(B, A)
        assert_equal(B.dtype, A.dtype)
        assert_equal(B.shape, A.shape)
        B[0, 0] = 'changed'
        assert_(B[0, 0] != A[0, 0])
        C = np.char.asarray(A)
        assert_array_equal(C, A)
        assert_equal(C.dtype, A.dtype)
        C[0, 0] = 'changed again'
        assert_(C[0, 0] != B[0, 0])
        assert_(C[0, 0] == A[0, 0]) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:18,代码来源:test_defchararray.py

示例15: test_ljust

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import string_ [as 别名]
def test_ljust(self):
        assert_(issubclass(self.A.ljust(10).dtype.type, np.string_))

        C = self.A.ljust([10, 20])
        assert_array_equal(np.char.str_len(C), [[10, 20], [10, 20], [12, 20]])

        C = self.A.ljust(20, asbytes('#'))
        assert_array_equal(C.startswith(asbytes('#')), [
                [False, True], [False, False], [False, False]])
        assert_(np.all(C.endswith(asbytes('#'))))

        C = np.char.ljust(asbytes('FOO'), [[10, 20], [15, 8]])
        tgt = asbytes_nested([['FOO       ', 'FOO                 '],
                              ['FOO            ', 'FOO     ']])
        assert_(issubclass(C.dtype.type, np.string_))
        assert_array_equal(C, tgt) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:18,代码来源:test_defchararray.py


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