bg dZddlZddlmZddlmZmZmZmZm Z m Z m Z ddl m Z mZddl mZdd lmZdd lmZdd lmZddlZgd Zdaejejd ZdZd`dZdZdZdZ ee dZ!ee dZ"ee dZ#ee dZ$ee dZ%ee dZ&dZ'ee'dZ(ee dZ)dZ*ee*dZ+dZ,ee,d Z-ee'd!Z.d`d"Z/ee/dad$Z0dbd%Z1ee1dcd&Z2dbd'Z3ee3dbd(Z4ee3dbd)Z5dbd*Z6ee6dcd+Z7d`d,Z8ee8ddd.Z9ee1dcd/Z:ee1dcd0Z;ee'd1Z<ee'd2Z=ee'd3Z>ee'd4Z?ee'd5Z@ee'd6ZAee'd7ZBd8ZCeeCd9ZDd`d:ZEeeEdad;ZFee'd<ZGd`d=ZHeeHd`d>ZId?ZJeeJd@ZKd`dAZLeeLd`dBZMee1dcdCZNee1dcdDZOeeEdadEZPeeJdFZQdbdGZReeRdbdHZSd`dIZHeeHd`dJZTeeRdbdKZUd`dLZVeeVd`dMZWdbdNZXeeXdcdOZYeeHd`dPZZee'dQZ[ee'dRZ\d`dSZ]ee]d`dTZ^ee'dUZ_dVZ`ee`dWZaee'dXZbee'dYZcedZGd[d\e Zded ded^Zed dfd_ZedS)gan This module contains a set of functions for vectorized string operations and methods. .. note:: The `chararray` class exists for backwards compatibility with Numarray, it is not recommended for new development. Starting from numpy 1.4, if one needs arrays of strings, it is recommended to use arrays of `dtype` `object_`, `bytes_` or `str_`, and use the free functions in the `numpy.char` module for fast vectorized string operations. Some methods will only be available if the corresponding string method is available in your version of Python. The preferred alias for `defchararray` is `numpy.char`. N) set_module)bytes_str_integerint_object_bool_ character)ndarraycompare_chararraysarray) _vec_string) overrides)asbytes)3equal not_equal greater_equal less_equalgreaterlessstr_lenaddmultiplymod capitalizecentercountdecodeencodeendswith expandtabsfindindexisalnumisalphaisdigitislowerisspaceistitleisupperjoinljustlowerlstrip partitionreplacerfindrindexrjust rpartitionrsplitrstripsplit splitlines startswithstripswapcasetitle translateupperzfill isnumeric isdecimalrasarrayz numpy.char)modulect|ts1ttj|jjtrdSdS)zReturns True if arr is a string or a string array with a dtype that represents a unicode string, otherwise returns False. TF) isinstancestr issubclassnumpyrEdtypetype)arrs N/opt/cloudlinux/venv/lib64/python3.11/site-packages/numpy/core/defchararray.py _is_unicoderP1sB 3 u}S))/4c : :t 5ctj|}t|dd}|:|t |t |dS|S)z Helper function to cast a result back into an array with the appropriate dtype if an object array must be used as an intermediary. rLNF)copy)rKrEtolistgetattrastyperM_get_num_chars)resultoutput_dtype_likeretrLs rO_to_bytes_or_str_arrayr[<sf -  ( (C %w 5 5E zz+$u++nS&9&9::zGGG JrQcFg}|D]}|n|||S)a! Helper function for delegating arguments to Python string functions. Many of the Python string operations that have optional arguments do not use 'None' to indicate a default value. In these cases, we need to remove all None arguments, and those following them. )append)argsnewargschks rO _clean_argsraIs<G ; Es NrQcbt|jjtr |jdzS|jS)z Helper function that returns the number of characters per field in a string or unicode array. This is to abstract out the fact that for a unicode array this is itemsize / 4. )rJrLrMritemsizeas rOrWrWYs. !',%%zQ :rQc ||fSNx1x2s rO_binary_op_dispatcherrmds 8OrQc&t||ddS)a Return (x1 == x2) element-wise. Unlike `numpy.equal`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray Output array of bools. See Also -------- not_equal, greater_equal, less_equal, greater, less z==Trrjs rOrrh. b"dD 1 11rQc&t||ddS)a Return (x1 != x2) element-wise. Unlike `numpy.not_equal`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray Output array of bools. See Also -------- equal, greater_equal, less_equal, greater, less z!=Trorjs rOrrrprQc&t||ddS)a Return (x1 >= x2) element-wise. Unlike `numpy.greater_equal`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray Output array of bools. See Also -------- equal, not_equal, less_equal, greater, less z>=Trorjs rOrrs0 b"dD 1 11rQc&t||ddS)a Return (x1 <= x2) element-wise. Unlike `numpy.less_equal`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray Output array of bools. See Also -------- equal, not_equal, greater_equal, greater, less z<=Trorjs rOrrrprQc&t||ddS)a Return (x1 > x2) element-wise. Unlike `numpy.greater`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray Output array of bools. See Also -------- equal, not_equal, greater_equal, less_equal, less >Trorjs rOrr. b"c4 0 00rQc&t||ddS)a Return (x1 < x2) element-wise. Unlike `numpy.greater`, this comparison is performed by first stripping whitespace characters from the end of the string. This behavior is provided for backward-compatibility with numarray. Parameters ---------- x1, x2 : array_like of str or unicode Input arrays of the same shape. Returns ------- out : ndarray Output array of bools. See Also -------- equal, not_equal, greater_equal, less_equal, greater >> a = np.array(['Grace Hopper Conference', 'Open Source Day']) >>> np.char.str_len(a) array([23, 15]) >>> a = np.array([u'Р', u'о']) >>> np.char.str_len(a) array([1, 1]) >>> a = np.array([['hello', 'world'], [u'Р', u'о']]) >>> np.char.str_len(a) array([[5, 5], [1, 1]]) __len__)rr res rOrr sB q$ * **rQctj|}tj|}t|t|z}t|jt|jkr t d|jd|jdt |t|j|d|fS)a 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 `bytes_` or `str_`, depending on input types of the same shape as `x1` and `x2`. zLnp.char.add() requires both arrays of the same dtype kind, but got dtypes: 'z' and 'zJ' (the few cases where this used to work often lead to incorrect results).__add__)rKrErWrMrL TypeErrorr)rkrlarr1arr2out_sizes rOrr-s* =  D =  Dd##nT&:&::H DJ4 ++++  H J H H/3z H H HII I t-T$*--h77TG L LLrQc|fSrhri)rfis rO_multiply_dispatcherrSr{rQctj|}tj|}t|jjt st dt|tt|dz}t|t |j|d|fS)a Return (a * i), that is string multiple concatenation, element-wise. Values in `i` of less than 0 are treated as 0 (which yields an empty string). Parameters ---------- a : array_like of str or unicode i : array_like of ints Returns ------- out : ndarray Output array of str or unicode, depending on input types Examples -------- >>> a = np.array(["a", "b", "c"]) >>> np.char.multiply(x, 3) array(['aaa', 'bbb', 'ccc'], dtype='>> i = np.array([1, 2, 3]) >>> np.char.multiply(a, i) array(['a', 'bb', 'ccc'], dtype='>> np.char.multiply(np.array(['a']), i) array(['a', 'aa', 'aaa'], dtype='>> a = np.array(['a', 'b', 'c', 'd', 'e', 'f']).reshape((2, 3)) >>> np.char.multiply(a, 3) array([['aaa', 'bbb', 'ccc'], ['ddd', 'eee', 'fff']], dtype='>> np.char.multiply(a, i) array([['a', 'bb', 'ccc'], ['d', 'ee', 'fff']], dtype='>> c = np.array(['a1b2','1b2a','b2a1','2a1b'],'S4'); c array(['a1b2', '1b2a', 'b2a1', '2a1b'], dtype='|S4') >>> np.char.capitalize(c) array(['A1b2', '1b2a', 'B2a1', '2a1b'], dtype='|S4') rrKrErrLrfrs rOrrs(F M!  E uek< 8 88rQc|fSrhrirfwidthfillchars rO_center_dispatcherrr{rQ cbtj|}tj|}ttj|j}tj|jtjrt|}t|t|j|d||fS)a\ Return a copy of `a` with its elements centered in a string of length `width`. Calls `str.center` element-wise. Parameters ---------- a : array_like of str or unicode width : int The length of the resulting strings fillchar : str or unicode, optional The padding character to use (default is space). Returns ------- out : ndarray Output array of str or unicode, depending on input types See Also -------- str.center Notes ----- This function is intended to work with arrays of strings. The fill character is not applied to numeric types. Examples -------- >>> c = np.array(['a1b2','1b2a','b2a1','2a1b']); c array(['a1b2', '1b2a', 'b2a1', '2a1b'], dtype='>> np.char.center(c, width=9) array([' a1b2 ', ' 1b2a ', ' b2a1 ', ' 2a1b '], dtype='>> np.char.center(c, width=9, fillchar='*') array(['***a1b2**', '***1b2a**', '***b2a1**', '***2a1b**'], dtype='>> np.char.center(c, width=1) array(['a', '1', 'b', '2'], dtype='>> c = np.array(['aAaAaA', ' aA ', 'abBABba']) >>> c array(['aAaAaA', ' aA ', 'abBABba'], dtype='>> np.char.count(c, 'A') array([3, 1, 1]) >>> np.char.count(c, 'aA') array([3, 1, 0]) >>> np.char.count(c, 'A', start=1, end=4) array([2, 1, 1]) >>> np.char.count(c, 'A', start=1, end=3) array([1, 0, 0]) r rr rars rOr r s*V q$#u C8H8H)H I IIrQc|fSrhrirfencodingerrorss rO_code_dispatcherr8r{rQc ftt|tdt||S)a Calls ``bytes.decode`` element-wise. The set of available codecs comes from the Python standard library, and may be extended at runtime. For more information, see the :mod:`codecs` module. Parameters ---------- a : array_like of str or unicode encoding : str, optional The name of an encoding errors : str, optional Specifies how to handle encoding errors Returns ------- out : ndarray See Also -------- :py:meth:`bytes.decode` Notes ----- The type of the result will depend on the encoding specified. Examples -------- >>> c = np.array([b'\x81\xc1\x81\xc1\x81\xc1', b'@@\x81\xc1@@', ... b'\x81\x82\xc2\xc1\xc2\x82\x81']) >>> c array([b'\x81\xc1\x81\xc1\x81\xc1', b'@@\x81\xc1@@', ... b'\x81\x82\xc2\xc1\xc2\x82\x81'], dtype='|S7') >>> np.char.decode(c, encoding='cp037') array(['aAaAaA', ' aA ', 'abBABba'], dtype='>> s = np.array(['foo', 'bar']) >>> s[0] = 'foo' >>> s[1] = 'bar' >>> s array(['foo', 'bar'], dtype='>> np.char.endswith(s, 'ar') array([False, True]) >>> np.char.endswith(s, 'a', start=1, end=2) array([False, True]) r#rr rars rOr#r#s4P  5*vuo C0@0@@ B BBrQc|fSrhrirftabsizes rO_expandtabs_dispatcherrr{rQcNtt|td|f|S)aS Return a copy of each string element where all tab characters are replaced by one or more spaces. Calls `str.expandtabs` element-wise. Return a copy of each string element where all tab characters are replaced by one or more spaces, depending on the current column and the given `tabsize`. The column number is reset to zero after each newline occurring in the string. This doesn't understand other non-printing characters or escape sequences. Parameters ---------- a : array_like of str or unicode Input array tabsize : int, optional Replace tabs with `tabsize` number of spaces. If not given defaults to 8 spaces. Returns ------- out : ndarray Output array of str or unicode, depending on input type See Also -------- str.expandtabs r$rrs rOr$r$s,@ "Aw wj991 > >>rQc Tt|td||gt|zS)a3 For each element, return the lowest index in the string where substring `sub` is found. Calls `str.find` element-wise. For each element, return the lowest index in the string where substring `sub` is found, such that `sub` is contained in the range [`start`, `end`]. Parameters ---------- a : array_like of str or unicode sub : str or unicode start, end : int, optional Optional arguments `start` and `end` are interpreted as in slice notation. Returns ------- out : ndarray or int Output array of ints. Returns -1 if `sub` is not found. See Also -------- str.find Examples -------- >>> a = np.array(["NumPy is a Python library"]) >>> np.char.find(a, "Python", start=0, end=None) array([11]) r%rrs rOr%r%s1L  4#u C(8(88 : ::rQc Tt|td||gt|zS)a Like `find`, but raises `ValueError` when the substring is not found. Calls `str.index` element-wise. Parameters ---------- a : array_like of str or unicode sub : str or unicode start, end : int, optional Returns ------- out : ndarray Output array of ints. Returns -1 if `sub` is not found. See Also -------- find, str.find Examples -------- >>> a = np.array(["Computer Science"]) >>> np.char.index(a, "Science", start=0, end=None) array([9]) r&rrs rOr&r&s0>  43,S)9)99 ; ;;rQc.t|tdS)a Returns true for each element if all characters in the string are alphanumeric and there is at least one character, false otherwise. Calls `str.isalnum` element-wise. For 8-bit strings, this method is locale-dependent. Parameters ---------- a : array_like of str or unicode Returns ------- out : ndarray Output array of str or unicode, depending on input type See Also -------- str.isalnum r'rr res rOr'r'3. q% + ++rQc.t|tdS)a Returns true for each element if all characters in the string are alphabetic and there is at least one character, false otherwise. Calls `str.isalpha` element-wise. For 8-bit strings, this method is locale-dependent. Parameters ---------- a : array_like of str or unicode Returns ------- out : ndarray Output array of bools See Also -------- str.isalpha r(rres rOr(r(MrrQc.t|tdS)a Returns true for each element if all characters in the string are digits and there is at least one character, false otherwise. Calls `str.isdigit` element-wise. For 8-bit strings, this method is locale-dependent. Parameters ---------- a : array_like of str or unicode Returns ------- out : ndarray Output array of bools See Also -------- str.isdigit Examples -------- >>> a = np.array(['a', 'b', '0']) >>> np.char.isdigit(a) array([False, False, True]) >>> a = np.array([['a', 'b', '0'], ['c', '1', '2']]) >>> np.char.isdigit(a) array([[False, False, True], [False, True, True]]) r)rres rOr)r)gs@ q% + ++rQc.t|tdS)a Returns true for each element if all cased characters in the string are lowercase and there is at least one cased character, false otherwise. Calls `str.islower` element-wise. For 8-bit strings, this method is locale-dependent. Parameters ---------- a : array_like of str or unicode Returns ------- out : ndarray Output array of bools See Also -------- str.islower r*rres rOr*r*0 q% + ++rQc.t|tdS)a Returns true for each element if there are only whitespace characters in the string and there is at least one character, false otherwise. Calls `str.isspace` element-wise. For 8-bit strings, this method is locale-dependent. Parameters ---------- a : array_like of str or unicode Returns ------- out : ndarray Output array of bools See Also -------- str.isspace r+rres rOr+r+rrQc.t|tdS)a Returns true for each element if the element is a titlecased string and there is at least one character, false otherwise. Call `str.istitle` element-wise. For 8-bit strings, this method is locale-dependent. Parameters ---------- a : array_like of str or unicode Returns ------- out : ndarray Output array of bools See Also -------- str.istitle r,rres rOr,r,rrQc.t|tdS)a Return true for each element if all cased characters in the string are uppercase and there is at least one character, false otherwise. Call `str.isupper` element-wise. For 8-bit strings, this method is locale-dependent. Parameters ---------- a : array_like of str or unicode Returns ------- out : ndarray Output array of bools See Also -------- str.isupper Examples -------- >>> str = "GHC" >>> np.char.isupper(str) array(True) >>> a = np.array(["hello", "HELLO", "Hello"]) >>> np.char.isupper(a) array([False, True, False]) r-rres rOr-r-sD q% + ++rQc ||fSrhrisepseqs rO_join_dispatcherrs :rQcNtt|td|f|S)a= Return a string which is the concatenation of the strings in the sequence `seq`. Calls `str.join` element-wise. Parameters ---------- sep : array_like of str or unicode seq : array_like of str or unicode Returns ------- out : ndarray Output array of str or unicode, depending on input types See Also -------- str.join Examples -------- >>> np.char.join('-', 'osd') array('o-s-d', dtype='>> np.char.join(['-', '.'], ['ghc', 'osd']) array(['g-h-c', 'o.s.d'], dtype=' "C&3&113 8 88rQc|fSrhrirs rO_just_dispatcherr'r{rQcbtj|}tj|}ttj|j}tj|jtjrt|}t|t|j|d||fS)a Return an array with the elements of `a` left-justified in a string of length `width`. Calls `str.ljust` element-wise. Parameters ---------- a : array_like of str or unicode width : int The length of the resulting strings fillchar : str or unicode, optional The character to use for padding Returns ------- out : ndarray Output array of str or unicode, depending on input type See Also -------- str.ljust r/rrs rOr/r/+6 M!  E e$$I uy(( ) )D  U\22%8$$   tEK  &&)X1F H HHrQcVtj|}t||jdS)ag Return an array with the elements converted to lowercase. Call `str.lower` element-wise. For 8-bit strings, this method is locale-dependent. Parameters ---------- a : array_like, {str, unicode} Input array. Returns ------- out : ndarray, {str, unicode} Output array of str or unicode, depending on input type See Also -------- str.lower Examples -------- >>> c = np.array(['A1B C', '1BCA', 'BCA1']); c array(['A1B C', '1BCA', 'BCA1'], dtype='>> np.char.lower(c) array(['a1b c', '1bca', 'bca1'], dtype=' M!  E uek7 3 33rQc|fSrhrirfcharss rO_strip_dispatcherrrr{rQcZtj|}t||jd|fS)am For each element in `a`, return a copy with the leading characters removed. Calls `str.lstrip` element-wise. Parameters ---------- a : array-like, {str, unicode} Input array. chars : {str, unicode}, optional The `chars` argument is a string specifying the set of characters to be removed. If omitted or None, the `chars` argument defaults to removing whitespace. The `chars` argument is not a prefix; rather, all combinations of its values are stripped. Returns ------- out : ndarray, {str, unicode} Output array of str or unicode, depending on input type See Also -------- str.lstrip Examples -------- >>> c = np.array(['aAaAaA', ' aA ', 'abBABba']) >>> c array(['aAaAaA', ' aA ', 'abBABba'], dtype='>> np.char.lstrip(c, 'a') array(['AaAaA', ' aA ', 'bBABba'], dtype='>> np.char.lstrip(c, 'A') # leaves c unchanged array(['aAaAaA', ' aA ', 'abBABba'], dtype='>> (np.char.lstrip(c, ' ') == np.char.lstrip(c, '')).all() ... # XXX: is this a regression? This used to return True ... # np.char.lstrip(c,'') does not modify c at all. False >>> (np.char.lstrip(c, ' ') == np.char.lstrip(c, None)).all() True r1rrfrrs rOr1r1vs,f M!  E uek8eX > >>rQc|fSrhrirfrs rO_partition_dispatcherrr{rQcNtt|td|f|S)aU Partition each element in `a` around `sep`. Calls `str.partition` element-wise. For each element in `a`, split the element as the first occurrence of `sep`, and return 3 strings containing the part before the separator, the separator itself, and the part after the separator. If the separator is not found, return 3 strings containing the string itself, followed by two empty strings. Parameters ---------- a : array_like, {str, unicode} Input array sep : {str, unicode} Separator to split each string element in `a`. Returns ------- out : ndarray, {str, unicode} Output array of str or unicode, depending on input type. The output array will have an extra dimension with 3 elements per input element. See Also -------- str.partition r2rrs rOr2r2s,@ "Aw cV44a 9 99rQc|fSrhrirfoldnewr s rO_replace_dispatcherrr{rQc ptt|td||gt|z|S)a For each element in `a`, return a copy of the string with all occurrences of substring `old` replaced by `new`. Calls `str.replace` element-wise. Parameters ---------- a : array-like of str or unicode old, new : str or unicode count : int, optional If the optional argument `count` is given, only the first `count` occurrences are replaced. Returns ------- out : ndarray Output array of str or unicode, depending on input type See Also -------- str.replace Examples -------- >>> a = np.array(["That is a mango", "Monkeys eat mangos"]) >>> np.char.replace(a, 'mango', 'banana') array(['That is a banana', 'Monkeys eat bananas'], dtype='>> a = np.array(["The dish is fresh", "This is it"]) >>> np.char.replace(a, 'is', 'was') array(['The dwash was fresh', 'Thwas was it'], dtype='J "Aw C: E8J8J+JKKQ P PPrQc Tt|td||gt|zS)a. For each element in `a`, return the highest index in the string where substring `sub` is found, such that `sub` is contained within [`start`, `end`]. Calls `str.rfind` element-wise. Parameters ---------- a : array-like of str or unicode sub : str or unicode start, end : int, optional Optional arguments `start` and `end` are interpreted as in slice notation. Returns ------- out : ndarray Output array of ints. Return -1 on failure. See Also -------- str.rfind r4rrs rOr4r4s0:  43,S)9)99 ; ;;rQc Tt|td||gt|zS)ax Like `rfind`, but raises `ValueError` when the substring `sub` is not found. Calls `str.rindex` element-wise. Parameters ---------- a : array-like of str or unicode sub : str or unicode start, end : int, optional Returns ------- out : ndarray Output array of ints. See Also -------- rfind, str.rindex r5rrs rOr5r5#s04  4C<+c*:*:: < <>> c = np.array(['aAaAaA', 'abBABba'], dtype='S7'); c array(['aAaAaA', 'abBABba'], dtype='|S7') >>> np.char.rstrip(c, b'a') array(['aAaAaA', 'abBABb'], dtype='|S7') >>> np.char.rstrip(c, b'A') array(['aAaAa', 'abBABba'], dtype='|S7') r9rrs rOr9r9s,R M!  E uek8eX > >>rQc Rt|td|gt|zS)a6 For each element in `a`, return a list of the words in the string, using `sep` as the delimiter string. Calls `str.split` element-wise. Parameters ---------- a : array_like of str or unicode sep : str or unicode, optional If `sep` is not specified or None, any whitespace string is a separator. maxsplit : int, optional If `maxsplit` is given, at most `maxsplit` splits are done. Returns ------- out : ndarray Array of list objects See Also -------- str.split, rsplit r:rrs rOr:r:s.>  7GcU[%:%:: < <>> c = np.array(['aAaAaA', ' aA ', 'abBABba']) >>> c array(['aAaAaA', ' aA ', 'abBABba'], dtype='>> np.char.strip(c) array(['aAaAaA', 'aA', 'abBABba'], dtype='>> np.char.strip(c, 'a') # 'a' unstripped from c[1] because whitespace leads array(['AaAaA', ' aA ', 'bBABb'], dtype='>> np.char.strip(c, 'A') # 'A' unstripped from c[1] because (unprinted) ws trails array(['aAaAa', ' aA ', 'abBABba'], dtype='>> c=np.array(['a1B c','1b Ca','b Ca1','cA1b'],'S5'); c array(['a1B c', '1b Ca', 'b Ca1', 'cA1b'], dtype='|S5') >>> np.char.swapcase(c) array(['A1b C', '1B cA', 'B cA1', 'Ca1B'], dtype='|S5') r>rrs rOr>r>zs(D M!  E uek: 6 66rQcVtj|}t||jdS)a Return element-wise title cased version of string or unicode. Title case words start with uppercase characters, all remaining cased characters are lowercase. Calls `str.title` element-wise. For 8-bit strings, this method is locale-dependent. Parameters ---------- a : array_like, {str, unicode} Input array. Returns ------- out : ndarray Output array of str or unicode, depending on input type See Also -------- str.title Examples -------- >>> c=np.array(['a1b c','1b ca','b ca1','ca1b'],'S5'); c array(['a1b c', '1b ca', 'b ca1', 'ca1b'], dtype='|S5') >>> np.char.title(c) array(['A1B C', '1B Ca', 'B Ca1', 'Ca1B'], dtype='|S5') r?rrs rOr?r?s(H M!  E uek7 3 33rQc|fSrhri)rftable deletecharss rO_translate_dispatcherrr{rQc tj|}t|jjt rt ||jd|fSt ||jd|gt|zS)a, For each element in `a`, return a copy of the string where all characters occurring in the optional argument `deletechars` are removed, and the remaining characters have been mapped through the given translation table. Calls `str.translate` element-wise. Parameters ---------- a : array-like of str or unicode table : str of length 256 deletechars : str Returns ------- out : ndarray Output array of str or unicode, depending on input type See Also -------- str.translate r@)rKrErJrLrMrrra)rfrrrs rOr@r@s{8 M!  E%+"D))Q 5; eX77 7 5; eW{;7O7O-OQQ QrQcVtj|}t||jdS)ah Return an array with the elements converted to uppercase. Calls `str.upper` element-wise. For 8-bit strings, this method is locale-dependent. Parameters ---------- a : array_like, {str, unicode} Input array. Returns ------- out : ndarray, {str, unicode} Output array of str or unicode, depending on input type See Also -------- str.upper Examples -------- >>> c = np.array(['a1b c', '1bca', 'bca1']); c array(['a1b c', '1bca', 'bca1'], dtype='>> np.char.upper(c) array(['A1B C', '1BCA', 'BCA1'], dtype='>> np.char.isnumeric(['123', '123abc', '9.0', '1/4', 'VIII']) array([ True, False, False, False, False]) z:isnumeric is only available for Unicode strings and arraysrCrPrrr res rOrCrC7s5@ q>>VTUUU q% - --rQcjt|stdt|tdS)a For each element, return True if there are only decimal characters in the element. Calls `str.isdecimal` element-wise. Decimal characters include digit characters, and all characters that can be used to form decimal-radix numbers, e.g. ``U+0660, ARABIC-INDIC DIGIT ZERO``. Parameters ---------- a : array_like, unicode Input array. Returns ------- out : ndarray, bool Array of booleans identical in shape to `a`. See Also -------- str.isdecimal Examples -------- >>> np.char.isdecimal(['12345', '4.99', '123ABC', '']) array([ True, False, False, False]) z:isdecimal is only available for Unicode strings and arraysrDr res rOrDrD\s>@ q>>J HJJ J q% - --rQrKceZdZdZ dAdZdZd Zd Zd Zd Z d Z dZ dZ dZ dZdZdZdZdZdBdZejje_dZdCdZdDdZdEdZdEdZdDdZdFd ZdDd!ZdDd"Zd#Zd$Zd%Z d&Z!d'Z"d(Z#d)Z$d*Z%dCd+Z&d,Z'dGd-Z(d.Z)dGd/Z*dDd0Z+dDd1Z,dCd2Z-d3Z.dEd4Z/dGd5Z0dEd6Z1dGd7Z2dDd8Z3dGd9Z4d:Z5d;Z6dGd<Z7d=Z8d>Z9d?Z:d@Z;dS)H chararraya chararray(shape, itemsize=1, unicode=False, buffer=None, offset=0, strides=None, order=None) Provides a convenient view on arrays of string and unicode values. .. note:: The `chararray` class exists for backwards compatibility with Numarray, it is not recommended for new development. Starting from numpy 1.4, if one needs arrays of strings, it is recommended to use arrays of `dtype` `object_`, `bytes_` or `str_`, and use the free functions in the `numpy.char` module for fast vectorized string operations. Versus a regular NumPy array of type `str` or `unicode`, this class adds the following functionality: 1) values automatically have whitespace removed from the end when indexed 2) comparison operators automatically remove whitespace from the end when comparing values 3) vectorized string operations are provided as methods (e.g. `.endswith`) and infix operators (e.g. ``"+", "*", "%"``) chararrays should be created using `numpy.char.array` or `numpy.char.asarray`, rather than this constructor directly. This constructor creates the array, using `buffer` (with `offset` and `strides`) if it is not ``None``. If `buffer` is ``None``, then constructs a new array with `strides` in "C order", unless both ``len(shape) >= 2`` and ``order='F'``, in which case `strides` is in "Fortran order". Methods ------- astype argsort copy count decode dump dumps encode endswith expandtabs fill find flatten getfield index isalnum isalpha isdecimal isdigit islower isnumeric isspace istitle isupper item join ljust lower lstrip nonzero put ravel repeat replace reshape resize rfind rindex rjust rsplit rstrip searchsorted setfield setflags sort split splitlines squeeze startswith strip swapaxes swapcase take title tofile tolist tostring translate transpose upper view zfill Parameters ---------- shape : tuple Shape of the array. itemsize : int, optional Length of each array element, in number of characters. Default is 1. unicode : bool, optional Are the array elements of type unicode (True) or string (False). Default is False. buffer : object exposing the buffer interface or str, optional Memory address of the start of the array data. Default is None, in which case a new array is created. offset : int, optional Fixed stride displacement from the beginning of an axis? Default is 0. Needs to be >=0. strides : array_like of ints, optional Strides for the array (see `ndarray.strides` for full description). Default is None. order : {'C', 'F'}, optional The order in which the array data is stored in memory: 'C' -> "row major" order (the default), 'F' -> "column major" (Fortran) order. Examples -------- >>> charar = np.chararray((3, 3)) >>> charar[:] = 'a' >>> charar chararray([[b'a', b'a', b'a'], [b'a', b'a', b'a'], [b'a', b'a', b'a']], dtype='|S1') >>> charar = np.chararray(charar.shape, itemsize=5) >>> charar[:] = 'abc' >>> charar chararray([[b'abc', b'abc', b'abc'], [b'abc', b'abc', b'abc'], [b'abc', b'abc', b'abc']], dtype='|S5') rFNrCc |rt}nt}t|}t|tr|} d}nd} da|t j||||f|} nt j||||f||||} | | | d<da| S)Nrorder)bufferoffsetstridesr.r)rrrrHrI _globalvarr __new__) subtypeshaperdunicoderrrrrLfillerselfs rOrzchararray.__new__s  EEE x== fc " " FFFF >?7EE83D).000DD?7EE83D*0*0').000D  DI  rQcRts|jjdvrtddSdS)NSUbcz-Can only create a chararray from string data.)rrLcharr)robjs rO__array_finalize__zchararray.__array_finalize__2s: NdjoV;;LMM M N N;;rQctj||}t|tr,|}t |dkrd}n|}|S)Nr)r __getitem__rHr r9len)rr"valtemps rOr&zchararray.__getitem__7sS!$,, c9 % % ::<= other) element-wise. See Also -------- greater_equal )rr+s rO__ge__zchararray.__ge__\sT5)))rQc"t||S)zl Return (self <= other) element-wise. See Also -------- less_equal )rr+s rO__le__zchararray.__le__fs$&&&rQc"t||S)zh Return (self > other) element-wise. See Also -------- greater )rr+s rO__gt__zchararray.__gt__pstU###rQc"t||S)ze Return (self < other) element-wise. See Also -------- less )rr+s rO__lt__zchararray.__lt__zsD%   rQc<tt||S)z Return (self + other), that is string concatenation, element-wise for a pair of array_likes of str or unicode. See Also -------- add )rErr+s rOrzchararray.__add__ss4''(((rQc`tttj||S)z Return (other + self), that is string concatenation, element-wise for a pair of array_likes of `bytes_` or `str_`. See Also -------- add )rErrKr+s rO__radd__zchararray.__radd__s&s5=//66777rQc<tt||Sz Return (self * i), that is string multiple concatenation, element-wise. See Also -------- multiply rErrrs rOrzchararray.__mul__xa(()))rQc<tt||Sr<r=r>s rO__rmul__zchararray.__rmul__r?rQc<tt||S)z Return (self % i), that is pre-Python 2.6 string formatting (interpolation), element-wise for a pair of array_likes of `bytes_` or `str_`. See Also -------- mod )rErr>s rOrzchararray.__mod__ss4||$$$rQctSrh)NotImplementedr+s rO__rmod__zchararray.__rmod__srQcT||||S)a Return the indices that sort the array lexicographically. For full documentation see `numpy.argsort`, for which this method is in fact merely a "thin wrapper." Examples -------- >>> c = np.array(['a1b c', '1b ca', 'b ca1', 'Ca1b'], 'S5') >>> c = c.view(np.chararray); c chararray(['a1b c', '1b ca', 'b ca1', 'Ca1b'], dtype='|S5') >>> c[c.argsort()] chararray(['1b ca', 'Ca1b', 'a1b c', 'b ca1'], dtype='|S5') ) __array__argsort)raxiskindrs rOrIzchararray.argsorts&$~~''dE:::rQc:tt|S)z Return a copy of `self` with only the first character of each element capitalized. See Also -------- char.capitalize )rErrs rOrzchararray.capitalizesz$''(((rQrc>tt|||S)z Return a copy of `self` with its elements centered in a string of length `width`. See Also -------- center )rErrrrs rOrzchararray.centersvdE844555rQc&t||||S)z Returns an array with the number of non-overlapping occurrences of substring `sub` in the range [`start`, `end`]. See Also -------- char.count )r rrrrs rOr zchararray.countsT3s+++rQc$t|||S)zn Calls ``bytes.decode`` element-wise. See Also -------- char.decode )r!rrrs rOr!zchararray.decodedHf---rQc$t|||S)zj Calls `str.encode` element-wise. See Also -------- char.encode )r"rSs rOr"zchararray.encode rTrQc&t||||S)z Returns a boolean array which is `True` where the string element in `self` ends with `suffix`, otherwise `False`. See Also -------- char.endswith )r#)rrrrs rOr#zchararray.endswith sfeS111rQrc<tt||S)z Return a copy of each string element where all tab characters are replaced by one or more spaces. See Also -------- char.expandtabs )rEr$)rrs rOr$zchararray.expandtabs sz$00111rQc&t||||S)z For each element, return the lowest index in the string where substring `sub` is found. See Also -------- char.find )r%rQs rOr%zchararray.find% sD#uc***rQc&t||||S)z Like `find`, but raises `ValueError` when the substring is not found. See Also -------- char.index )r&rQs rOr&zchararray.index1 sT3s+++rQc t|S)z Returns true for each element if all characters in the string are alphanumeric and there is at least one character, false otherwise. See Also -------- char.isalnum )r'rMs rOr'zchararray.isalnum< t}}rQc t|S)z Returns true for each element if all characters in the string are alphabetic and there is at least one character, false otherwise. See Also -------- char.isalpha )r(rMs rOr(zchararray.isalphaI r[rQc t|S)z Returns true for each element if all characters in the string are digits and there is at least one character, false otherwise. See Also -------- char.isdigit )r)rMs rOr)zchararray.isdigitV t}}rQc t|S)z Returns true for each element if all cased characters in the string are lowercase and there is at least one cased character, false otherwise. See Also -------- char.islower )r*rMs rOr*zchararray.islowerb r[rQc t|S)z Returns true for each element if there are only whitespace characters in the string and there is at least one character, false otherwise. See Also -------- char.isspace )r+rMs rOr+zchararray.isspaceo r[rQc t|S)z Returns true for each element if the element is a titlecased string and there is at least one character, false otherwise. See Also -------- char.istitle )r,rMs rOr,zchararray.istitle| r^rQc t|S)z Returns true for each element if all cased characters in the string are uppercase and there is at least one character, false otherwise. See Also -------- char.isupper )r-rMs rOr-zchararray.isupper r[rQc"t||S)z Return a string which is the concatenation of the strings in the sequence `seq`. See Also -------- char.join )r.)rrs rOr.zchararray.join sD#rQc>tt|||S)z Return an array with the elements of `self` left-justified in a string of length `width`. See Also -------- char.ljust )rEr/rOs rOr/zchararray.ljust uT5(33444rQc:tt|S)z Return an array with the elements of `self` converted to lowercase. See Also -------- char.lower )rEr0rMs rOr0zchararray.lower uT{{###rQc<tt||S)z For each element in `self`, return a copy with the leading characters removed. See Also -------- char.lstrip )rEr1rrs rOr1zchararray.lstrip vdE**+++rQc<tt||S)zu Partition each element in `self` around `sep`. See Also -------- partition )rEr2rrs rOr2zchararray.partition sys++,,,rQc@tt||||S)z For each element in `self`, return a copy of the string with all occurrences of substring `old` replaced by `new`. See Also -------- char.replace )rEr3)rrrr s rOr3zchararray.replace s wtS#u55666rQc&t||||S)z For each element in `self`, return the highest index in the string where substring `sub` is found, such that `sub` is contained within [`start`, `end`]. See Also -------- char.rfind )r4rQs rOr4zchararray.rfind sT3s+++rQc&t||||S)z Like `rfind`, but raises `ValueError` when the substring `sub` is not found. See Also -------- char.rindex )r5rQs rOr5zchararray.rindex sdC,,,rQc>tt|||S)z Return an array with the elements of `self` right-justified in a string of length `width`. See Also -------- char.rjust )rEr6rOs rOr6zchararray.rjust rerQc<tt||S)zv Partition each element in `self` around `sep`. See Also -------- rpartition )rEr7rls rOr7zchararray.rpartition sz$,,---rQc$t|||S)z For each element in `self`, return a list of the words in the string, using `sep` as the delimiter string. See Also -------- char.rsplit )r8rrrs rOr8zchararray.rsplit sdC***rQc<tt||S)z For each element in `self`, return a copy with the trailing characters removed. See Also -------- char.rstrip )rEr9ris rOr9zchararray.rstrip rjrQc$t|||S)z For each element in `self`, return a list of the words in the string, using `sep` as the delimiter string. See Also -------- char.split )r:rss rOr:zchararray.split" sT3)))rQc"t||S)z For each element in `self`, return a list of the lines in the element, breaking at line boundaries. See Also -------- char.splitlines )r;)rrs rOr;zchararray.splitlines. s$)))rQc&t||||S)z Returns a boolean array which is `True` where the string element in `self` starts with `prefix`, otherwise `False`. See Also -------- char.startswith )r<)rrrrs rOr<zchararray.startswith: s$s333rQc<tt||S)z For each element in `self`, return a copy with the leading and trailing characters removed. See Also -------- char.strip )rEr=ris rOr=zchararray.stripF uT5))***rQc:tt|S)z For each element in `self`, return a copy of the string with uppercase characters converted to lowercase and vice versa. See Also -------- char.swapcase )rEr>rMs rOr>zchararray.swapcaseR sx~~&&&rQc:tt|S)z For each element in `self`, return a titlecased version of the string: words start with uppercase characters, all remaining cased characters are lowercase. See Also -------- char.title )rEr?rMs rOr?zchararray.title^ suT{{###rQc>tt|||S)aB For each element in `self`, return a copy of the string where all characters occurring in the optional argument `deletechars` are removed, and the remaining characters have been mapped through the given translation table. See Also -------- char.translate )rEr@)rrrs rOr@zchararray.translatek syuk::;;;rQc:tt|S)z Return an array with the elements of `self` converted to uppercase. See Also -------- char.upper )rErArMs rOrAzchararray.uppery rgrQc<tt||S)z Return the numeric string left-filled with zeros in a string of length `width`. See Also -------- char.zfill )rErB)rrs rOrBzchararray.zfill ryrQc t|S)z For each element in `self`, return True if there are only numeric characters in the element. See Also -------- char.isnumeric )rCrMs rOrCzchararray.isnumeric rQc t|S)z For each element in `self`, return True if there are only decimal characters in the element. See Also -------- char.isdecimal )rDrMs rOrDzchararray.isdecimal rrQ)rFNrNr)rFNNrrNNNrrh)<__name__ __module__ __qualname____doc__rr#r&r-r/r1r3r5r7rr:rrArrErIr rrr r!r"r#r$r%r&r'r(r)r*r+r,r-r.r/r0r1r2r3r4r5r6r7r8r9r:r;r<r=r>r?r@rArBrCrDrirQrOrrsJJVCG.1!!!!FNNN   """"&&&***'''$$$!!! ) ) ) 8 8 8 * * * * * * % % %;;;;&o-GO ) ) ) 6 6 6 6 , , , , . . . . . . . . 2 2 2 2 2 2 2 2 + + + + , , , ,                         5 5 5 5 $ $ $ , , , ,--- 7 7 7 7 , , , , - - - - 5 5 5 5... + + + + , , , , * * * * * * * * 4 4 4 4 + + + + ' ' ' $ $ $ < < < < $ $ $ + + +        rQrTct|ttfrS|t|trd}nd}|t|}t||z}t |||||St|t t frtj|}t|tr,t|j j tr t|ts|t}|+|j}t|j j t r|dz}|$t|j j t rd}nd}|rt }nt"}|tj||}|s9||jks.|st|t s|r9t|t"r$||t'|f}|St|tr5t|j j t(r||}|rt }nt"}|t-|||d}nt-|||f|d}|tS)a Create a `chararray`. .. note:: This class is provided for numarray backward-compatibility. New code (not concerned with numarray compatibility) should use arrays of type `bytes_` or `str_` and use the free functions in :mod:`numpy.char ` for fast vectorized string operations instead. Versus a regular NumPy array of type `str` or `unicode`, this class adds the following functionality: 1) values automatically have whitespace removed from the end when indexed 2) comparison operators automatically remove whitespace from the end when comparing values 3) vectorized string operations are provided as methods (e.g. `str.endswith`) and infix operators (e.g. ``+, *, %``) Parameters ---------- obj : array of str or unicode-like itemsize : int, optional `itemsize` is the number of characters per scalar in the resulting array. If `itemsize` is None, and `obj` is an object array or a Python list, the `itemsize` will be automatically determined. If `itemsize` is provided and `obj` is of type str or unicode, then the `obj` string will be chunked into `itemsize` pieces. copy : bool, optional If true (default), then the object is copied. Otherwise, a copy will only be made if __array__ returns a copy, if obj is a nested sequence, or if a copy is needed to satisfy any of the other requirements (`itemsize`, unicode, `order`, etc.). unicode : bool, optional When true, the resulting `chararray` can contain Unicode characters, when false only 8-bit characters. If unicode is None and `obj` is one of the following: - a `chararray`, - an ndarray of type `str` or `unicode` - a Python str or unicode object, then the unicode setting of the output array will be automatically determined. order : {'C', 'F', 'A'}, optional Specify the order of the array. If order is 'C' (default), then the array will be in C-contiguous order (last-index varies the fastest). If order is 'F', then the returned array will be in Fortran-contiguous order (first-index varies the fastest). If order is 'A', then the returned array may be in any order (either C-, Fortran-contiguous, or even discontiguous). NTF)rdrrrrcr)rLrsubok)rHbytesrIr'rlisttuplerKrEr rJrLrMr viewrdrrrVrobjectrTnarray)r"rdrSrrrrLr(s rOrr s~#s|$$ 2 ?#s##   3xxHCH$7 #5222 2#e}%%!mC  #w Jsy~y$I$I #y)) &((9%%C  |H#).$// Q ?#).$//   EEE  -5111C  5S\))*!+C!6!6**'V44***eS]]344C #wJsy~v$F$F  **,,CSU$???S 1dKKK 88I  rQc*t||d||S)a Convert the input to a `chararray`, copying the data only if necessary. Versus a regular NumPy array of type `str` or `unicode`, this class adds the following functionality: 1) values automatically have whitespace removed from the end when indexed 2) comparison operators automatically remove whitespace from the end when comparing values 3) vectorized string operations are provided as methods (e.g. `str.endswith`) and infix operators (e.g. ``+``, ``*``,``%``) Parameters ---------- obj : array of str or unicode-like itemsize : int, optional `itemsize` is the number of characters per scalar in the resulting array. If `itemsize` is None, and `obj` is an object array or a Python list, the `itemsize` will be automatically determined. If `itemsize` is provided and `obj` is of type str or unicode, then the `obj` string will be chunked into `itemsize` pieces. unicode : bool, optional When true, the resulting `chararray` can contain Unicode characters, when false only 8-bit characters. If unicode is None and `obj` is one of the following: - a `chararray`, - an ndarray of type `str` or 'unicode` - a Python str or unicode object, then the unicode setting of the output array will be automatically determined. order : {'C', 'F'}, optional Specify the order of the array. If order is 'C' (default), then the array will be in C-contiguous order (last-index varies the fastest). If order is 'F', then the returned array will be in Fortran-contiguous order (first-index varies the fastest). F)rSrrr)r"rdrrs rOrErE0 s'b hU  / / //rQrhrrrr)NTNN)NNN)fr functools_utilsr numerictypesrrrr r r r numericr rrrnumpy.core.multiarrayr numpy.corer numpy.compatrrK__all__rpartialarray_function_dispatchrPr[rarWrmrrrrrrrzrrrrrrrrrrr rr!r"rr#rr$r%r&r'r(r)r*r+r,r-rr.rr/r0rr1rr2rr3r4r5r6r7rr8r9r:rr;rr<r=r>r?rr@rAr rBrCrDrrErirQrOrs "<<<<<<<<<<<<<<<<<<00000000$$$$$$------     +)+ %l<<<     .//220/22.//220/22.//220/24.//220/22.//110/12.//110/12-.. + +/. +F.//#M#M0/#MJ-..+A+A/.+A\))::*):6-..#9#9/.#9L+,,1I1I1I-,1Ih*++*J*J*J,+*JZ)***J*J*J+**JZ)** J J J+* JF-..(B(B(B/.(BV/00 > > >10 >F*++&:&:&:,+&:R*++;;;,+;D-..,,/.,2-..,,/.,2-..,,/.,D-..,,/.,4-..,,/.,4-..,,/.,2-..!,!,/.!,H)**88+*8F)** H H H+* HF-..44/.4D*++3?3?3?,+3?l.// 9 90/ 9F,--%P%P%P.-%PP*++;;;,+;@*++<<<,+<:)** H H H+* HF.// : :0/ :F*++"="="=,+"=J*++)?)?)?,+)?X*++<<<,+*++)H)H)H,+)HX-.."7"7/."7J-..$4$4/.$4N.//!Q!Q!Q0/!QH-..44/.4D*++??,+?<-..!.!./.!.H-.."."./.".J Gd d d d d d d d N LBBBBJ L1/1/1/1/1/1/rQ