當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。