U C^D3@sdZddlmZmZmZddlZddlZddlmZm Z m Z m Z m Z m Z ddlmZmZddlmZddlmZdd lmZdd lmZdd lmZmZddlZd d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;dg3Zdaejdd?kr(e Z!e"Z#ne$Z!e Z#e%Z&ej'ej(d@dAZ(dBdCZ)dDdEZ*dFdGZ+dHdIZ,dJdKZ-e(e-dLd Z.e(e-dMd Z/e(e-dNdZ0e(e-dOdZ1e(e-dPdZ2e(e-dQdZ3dRdSZ4e(e4dTdZ5e(e-dUdZ6dVdWZ7e(e7dXdZ8dYdZZ9e(e9d[dZ:e(e4d\dZ;dd]d^Ze(e>ddcdZ?ddddeZ@e(e@ddfdZAe(e@ddgdZBddhdiZCe(eCddjdZDddkdlZEe(eEddndZFe(e>ddodZGe(e>ddpdZHe(e4dqdZIe(e4drd ZJe(e4dsd!ZKe(e4dtd"ZLe(e4dud#ZMe(e4dvd$ZNe(e4dwd%ZOdxdyZPe(ePdzd&ZQdd{d|ZRe(eRdd}d'ZSe(e4d~d(ZTdddZUe(eUddd)ZVddZWe(eWdd*ZXdddZYe(eYddd+ZZe(e>ddd,Z[e(e>ddd-Z\e(eRddd.Z]e(eWdd/Z^dddZ_e(e_ddd0Z`dddZUe(eUddd1Zae(e_ddd2ZbdddZce(ecddd3ZddddZee(eeddd4Zfe(eUddd5Zge(e4dd6Zhe(e4dd7ZidddZje(ejddd8Zke(e4dd9ZlddZme(emdd:Zne(e4dd;Zoe(e4dd<ZpedGdddeZqddd=Zddd>ZrdS)as 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_`, `string_` or `unicode_`, 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`. )divisionabsolute_importprint_functionN)string_unicode_integerobject_bool_ character)ndarraycompare_chararraysarray) _vec_string) set_module) overrides)asbyteslongequal not_equal greater_equal less_equalgreaterlessstr_lenaddmultiplymod capitalizecentercountdecodeencodeendswith expandtabsfindindexisalnumisalphaisdigitislowerisspaceistitleisupperjoinljustlowerlstrip partitionreplacerfindrindexrjust rpartitionrsplitrstripsplit splitlines startswithstripswapcasetitle translateupperzfill isnumeric isdecimalrasarrayz numpy.char)modulecGs4|D]*}t|ts&tt|jjtrtSqtS)z Helper function for determining the output type of some string operations. For an operation on two ndarrays, if at least one is unicode, the result should be unicode. ) isinstance_unicode issubclassnumpyrFdtypetyperr)argsxrQ:/tmp/pip-install-6_kvzl1k/numpy/numpy/core/defchararray.py _use_unicode9s   rScCst|S)z Helper function to cast a result back into a string or unicode array if an object array must be used as an intermediary. )rLrFtolist)resultrQrQrR_to_string_or_unicode_arrayGsrVcGs(g}|D]}|dkrq$||q|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. N)append)rOZnewargsZchkrQrQrR _clean_argsNs  rXcCst|jjtr|jdS|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. )rKrMrNritemsizearQrQrR_get_num_chars^s r]cCs||fSNrQx1x2rQrQrR_binary_op_dispatcherisrbcCst||ddS)a4 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 or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- not_equal, greater_equal, less_equal, greater, less z==Tr r_rQrQrRrmscCst||ddS)a4 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 or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- equal, greater_equal, less_equal, greater, less z!=Trcr_rQrQrRrscCst||ddS)a7 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 or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- equal, not_equal, less_equal, greater, less z>=Trcr_rQrQrRrscCst||ddS)a4 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 or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- equal, not_equal, greater_equal, greater, less z<=Trcr_rQrQrRrscCst||ddS)a3 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 or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- equal, not_equal, greater_equal, less_equal, less >Trcr_rQrQrRrscCst||ddS)a6 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 or bool Output array of bools, or a single bool if x1 and x2 are scalars. See Also -------- equal, not_equal, greater_equal, less_equal, greater >> 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') rrLrFrrMr\rorQrQrRrs# cCs|fSr^rQr\widthfillcharrQrQrR_center_dispatchersrz cCsVt|}t|}tt|j}t|jtjr>> 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!rrrXrrQrQrRr!s+cCs|fSr^rQr\encodingerrorsrQrQrR_code_dispatchersrcCstt|tdt||S)a} Calls `str.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 -------- str.decode Notes ----- The type of the result will depend on the encoding specified. Examples -------- >>> c = np.array(['aAaAaA', ' aA ', 'abBABba']) >>> c array(['aAaAaA', ' aA ', 'abBABba'], dtype='>> np.char.encode(c, encoding='cp037') array(['\x81\xc1\x81\xc1\x81\xc1', '@@\x81\xc1@@', '\x81\x82\xc2\xc1\xc2\x82\x81'], dtype='|S7') r"rVrr rXrrQrQrRr"s*cCstt|tdt||S)aA Calls `str.encode` element-wise. The set of available codecs comes from the Python standard library, and may be extended at runtime. For more information, see the 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 -------- str.encode Notes ----- The type of the result will depend on the encoding specified. r#rrrQrQrRr#5s cCs|fSr^rQr\suffixrrrQrQrR_endswith_dispatcherYsrcCst|td||gt|S)a5 Returns a boolean array which is `True` where the string element in `a` ends with `suffix`, otherwise `False`. Calls `str.endswith` element-wise. Parameters ---------- a : array_like of str or unicode suffix : str start, end : int, optional With optional `start`, test beginning at that position. With optional `end`, stop comparing at that position. Returns ------- out : ndarray Outputs an array of bools. See also -------- str.endswith Examples -------- >>> 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 rXrrQrQrRr$]s (cCs|fSr^rQr\tabsizerQrQrR_expandtabs_dispatchersrcCstt|td|fS)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%rtrrQrQrRr%s cCst|td||gt|S)a 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 r&rrrQrQrRr&s cCst|td||gt|S)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 r'rrrQrQrRr's cCs 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 r[rQrQrRr(scCs 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)rr[rQrQrRr) scCs 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 r*rr[rQrQrRr*&scCs 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+rr[rQrQrRr+@scCs 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,rr[rQrQrRr,[scCs 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-rr[rQrQrRr-vscCs t|tdS)a Returns 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 r.rr[rQrQrRr.scCs||fSr^rQsepseqrQrQrR_join_dispatchersrcCstt|td|fS)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 r/rtrrQrQrRr/scCs|fSr^rQrwrQrQrR_just_dispatchersrcCsVt|}t|}tt|j}t|jtjr>> c = np.array(['A1B C', '1BCA', 'BCA1']); c array(['A1B C', '1BCA', 'BCA1'], dtype='>> np.char.lower(c) array(['a1b c', '1bca', 'bca1'], dtype='>> 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 r2rur\rrorQrQrRr2s3 cCs|fSr^rQr\rrQrQrR_partition_dispatcherPsrcCstt|td|fS)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 r3rtrrQrQrRr3Ts cCs|fSr^rQr\oldnewr!rQrQrR_replace_dispatcherxsrcCstt|td||gt|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 r4rrrQrQrRr4|scCst|td||gt|S)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 r5rrrQrQrRr5s cCst|td||gt|S)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 r6rrrQrQrRr6s cCsVt|}t|}tt|j}t|jtjr>> 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') r:rurrQrQrRr:Rs) cCst|td|gt|S)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;rrrQrQrRr;s  cCs|fSr^rQr\keependsrQrQrR_splitlines_dispatchersrcCst|tdt|S)a For each element in `a`, return a list of the lines in the element, breaking at line boundaries. Calls `str.splitlines` element-wise. Parameters ---------- a : array_like of str or unicode keepends : bool, optional Line breaks are not included in the resulting list unless keepends is given and true. Returns ------- out : ndarray Array of list objects See also -------- str.splitlines r<rrrQrQrRr<s cCs|fSr^rQr\prefixrrrQrQrR_startswith_dispatchersrcCst|td||gt|S)a Returns a boolean array which is `True` where the string element in `a` starts with `prefix`, otherwise `False`. Calls `str.startswith` element-wise. Parameters ---------- a : array_like of str or unicode prefix : str start, end : int, optional With optional `start`, test beginning at that position. With optional `end`, stop comparing at that position. Returns ------- out : ndarray Array of booleans See also -------- str.startswith r=rrrQrQrRr=s cCst|}t||jdt|S)a For each element in `a`, return a copy with the leading and trailing characters removed. Calls `str.strip` element-wise. Parameters ---------- a : array-like of str or unicode chars : str or 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 or suffix; rather, all combinations of its values are stripped. Returns ------- out : ndarray Output array of str or unicode, depending on input type See also -------- str.strip Examples -------- >>> 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=')rLrFrrMrXrrQrQrRr>s) cCst|}t||jdS)a Return element-wise a copy of the string with uppercase characters converted to lowercase and vice versa. Calls `str.swapcase` 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.swapcase 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.swapcase(c) array(['A1b C', '1B cA', 'B cA1', 'Ca1B'], dtype='|S5') r?rurvrQrQrRr?s" cCst|}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@rurvrQrQrRr@;s$ cCs|fSr^rQ)r\table deletecharsrQrQrR_translate_dispatchercsrcCsHt|}t|jjtr*t||jd|fSt||jd|gt|SdS)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 rAN)rLrFrKrMrNrrrX)r\rrrorQrQrRrAgs  cCst|}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='d?Zd@dAZ dBdCZ!dDdEZ"dFdGZ#dHdIZ$dJdKZ%ddLdMZ&dNdOZ'ddPdQZ(dRdSZ)ddTdUZ*ddVdWZ+ddXdYZ,ddZd[Z-d\d]Z.dd^d_Z/dd`daZ0ddbdcZ1ddddeZ2ddfdgZ3ddhdiZ4djdkZ5dldmZ6ddndoZ7dpdqZ8drdsZ9dtduZ:dvdwZ;dS) 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_`, `string_` or `unicode_`, 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 : int, 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 Cs|r t}nt}t|}tjddkr8t|tr8|} d}nd} da|dkr`tj ||||f|d} ntj ||||f||||d} | dk r| | d<da| S)NrrGrorder)bufferoffsetstridesr.) rrrsys version_inforIrJ _globalvarr __new__) subtypeshaperZunicoderrrrrMZfillerselfrQrQrRrs.zchararray.__new__cCsts|jjdkrtddS)NZSUbcz-Can only create a chararray from string data.)rrMcharrm)robjrQrQrR__array_finalize__szchararray.__array_finalize__cCs8t||}t|tr4|}t|dkr0d}n|}|S)Nr)r __getitem__rIr r:_len)rrvaltemprQrQrRrs   zchararray.__getitem__cCs t||S)zg Return (self == other) element-wise. See also -------- equal )rrotherrQrQrR__eq__szchararray.__eq__cCs t||S)zk Return (self != other) element-wise. See also -------- not_equal )rrrQrQrR__ne__szchararray.__ne__cCs t||S)zo Return (self >= other) element-wise. See also -------- greater_equal )rrrQrQrR__ge__szchararray.__ge__cCs t||S)zl Return (self <= other) element-wise. See also -------- less_equal )rrrQrQrR__le__szchararray.__le__cCs t||S)zh Return (self > other) element-wise. See also -------- greater )rrrQrQrR__gt__szchararray.__gt__cCs t||S)ze Return (self < other) element-wise. See also -------- less )rrrQrQrR__lt__ szchararray.__lt__cCstt||S)z Return (self + other), that is string concatenation, element-wise for a pair of array_likes of str or unicode. See also -------- add )rFrrrQrQrRrhs zchararray.__add__cCsttt||S)z Return (other + self), that is string concatenation, element-wise for a pair of array_likes of `string_` or `unicode_`. See also -------- add )rFrrLrrQrQrR__radd__s zchararray.__radd__cCstt||Sz Return (self * i), that is string multiple concatenation, element-wise. See also -------- multiply rFrrrjrQrQrRrl*s zchararray.__mul__cCstt||SrrrrQrQrR__rmul__5s zchararray.__rmul__cCstt||S)z Return (self % i), that is pre-Python 2.6 string formatting (iterpolation), element-wise for a pair of array_likes of `string_` or `unicode_`. See also -------- mod )rFrrrQrQrRrs@s zchararray.__mod__cCstSr^)NotImplementedrrQrQrR__rmod__Lszchararray.__rmod__cCs||||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') )Z __array__argsort)rZaxiskindrrQrQrRrOszchararray.argsortcCs tt|S)z Return a copy of `self` with only the first character of each element capitalized. See also -------- char.capitalize )rFrrrQrQrRrds zchararray.capitalizer{cCstt|||S)z Return a copy of `self` with its elements centered in a string of length `width`. See also -------- center )rFr rrxryrQrQrRr ps zchararray.centercCst||||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!rrrrrQrQrRr!{s zchararray.countcCs t|||S)zj Calls `str.decode` element-wise. See also -------- char.decode )r"rrrrQrQrRr"s zchararray.decodecCs t|||S)zj Calls `str.encode` element-wise. See also -------- char.encode )r#rrQrQrRr#s zchararray.encodecCst||||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$)rrrrrQrQrRr$s zchararray.endswithrcCstt||S)z Return a copy of each string element where all tab characters are replaced by one or more spaces. See also -------- char.expandtabs )rFr%)rrrQrQrRr%s zchararray.expandtabscCst||||S)z For each element, return the lowest index in the string where substring `sub` is found. See also -------- char.find )r&rrQrQrRr&s zchararray.findcCst||||S)z Like `find`, but raises `ValueError` when the substring is not found. See also -------- char.index )r'rrQrQrRr's zchararray.indexcCst|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(rrQrQrRr(s zchararray.isalnumcCst|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)rrQrQrRr)s zchararray.isalphacCst|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*rrQrQrRr*s zchararray.isdigitcCst|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+rrQrQrRr+s zchararray.islowercCst|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,rrQrQrRr,s zchararray.isspacecCst|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-rrQrQrRr- s zchararray.istitlecCst|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.rrQrQrRr. s zchararray.isuppercCs t||S)z Return a string which is the concatenation of the strings in the sequence `seq`. See also -------- char.join )r/)rrrQrQrRr/% s zchararray.joincCstt|||S)z Return an array with the elements of `self` left-justified in a string of length `width`. See also -------- char.ljust )rFr0rrQrQrRr01 s zchararray.ljustcCs tt|S)z Return an array with the elements of `self` converted to lowercase. See also -------- char.lower )rFr1rrQrQrRr1= s zchararray.lowercCstt||S)z For each element in `self`, return a copy with the leading characters removed. See also -------- char.lstrip )rFr2rrrQrQrRr2I s zchararray.lstripcCstt||S)zu Partition each element in `self` around `sep`. See also -------- partition )rFr3rrrQrQrRr3U szchararray.partitioncCstt||||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 )rFr4)rrrr!rQrQrRr4_ s zchararray.replacecCst||||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 )r5rrQrQrRr5k s zchararray.rfindcCst||||S)z Like `rfind`, but raises `ValueError` when the substring `sub` is not found. See also -------- char.rindex )r6rrQrQrRr6x s zchararray.rindexcCstt|||S)z Return an array with the elements of `self` right-justified in a string of length `width`. See also -------- char.rjust )rFr7rrQrQrRr7 s zchararray.rjustcCstt||S)zv Partition each element in `self` around `sep`. See also -------- rpartition )rFr8rrQrQrRr8 szchararray.rpartitioncCs 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 )r9rrrrQrQrRr9 s zchararray.rsplitcCstt||S)z For each element in `self`, return a copy with the trailing characters removed. See also -------- char.rstrip )rFr:rrQrQrRr: s zchararray.rstripcCs 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;rrQrQrRr; s zchararray.splitcCs 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<)rrrQrQrRr< s zchararray.splitlinescCst||||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=)rrrrrQrQrRr= s zchararray.startswithcCstt||S)z For each element in `self`, return a copy with the leading and trailing characters removed. See also -------- char.strip )rFr>rrQrQrRr> s zchararray.stripcCs 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 )rFr?rrQrQrRr? s zchararray.swapcasecCs 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 )rFr@rrQrQrRr@ s zchararray.titlecCstt|||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 )rFrA)rrrrQrQrRrA s zchararray.translatecCs tt|S)z Return an array with the elements of `self` converted to uppercase. See also -------- char.upper )rFrBrrQrQrRrB s zchararray.uppercCstt||S)z Return the numeric string left-filled with zeros in a string of length `width`. See also -------- char.zfill )rFrC)rrxrQrQrRrC s zchararray.zfillcCst|S)z For each element in `self`, return True if there are only numeric characters in the element. See also -------- char.isnumeric )rDrrQrQrRrD! s zchararray.isnumericcCst|S)z For each element in `self`, return True if there are only decimal characters in the element. See also -------- char.isdecimal )rErrQrQrRrE- s zchararray.isdecimal)rFNrNr)rNN)r{)rN)NN)NN)rN)r)rN)rN)r{)N)N)rN)rN)r{)NN)N)NN)N)rN)N)N)<__name__ __module__ __qualname____doc__rrrrrrrrrrhrrlrrsrrr rr r!r"r#r$r%r&r'r(r)r*r+r,r-r.r/r0r1r2r3r4r5r6r7r8r9r:r;r<r=r>r?r@rArBrCrDrErQrQrQrRrs|  #                              rTcCst|ttfr|dkr*t|tr&d}nd}|dkr:t|}t||}|rjtjdkr`|d}qrt|}nt|}t|||||dSt|tt frt |}t|t rt |jjtrt|ts|t}|dkr|j}t |jjtr|d}|dkrt |jjtrd}nd}|r t}nt}|dk r` 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). NTFiutf_32)rZrrrrYr)rMrZsubok)rI_bytesrJrr maxunicoder#rlisttuplerLrFr rKrMrNr viewrZrrZastyperobjectrTnarray)rrZcopyrrrrMrrQrQrRr: st>           cCst||d||dS)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)rrrr)rrZrrrQrQrRrF s0)N)r{)NN)rN)NN)NN)NN)NN)rN)N)r)rN)rN)N)r{)N)N)N)N)rN)rN)r{)NN)NN)N)N)NN)N)N)NN)rN)N)N)N)NTNN)NNN)sr __future__rrr functoolsrZ numerictypesrrrr r r numericr r rrZnumpy.core.multiarrayrZnumpy.core.overridesrZ numpy.corerZ numpy.compatrrrL__all__rrstrrJbytesrrlenrpartialZarray_function_dispatchrSrVrXr]rbrrrrrrrfrrrkrrrrrrzr rr!rr"r#rr$rr%r&r'r(r)r*r+r,r-r.rr/rr0r1rr2rr3rr4r5r6r7r8rr9r:r;rr<rr=r>r?r@rrArBrrCrDrErrFrQrQrQrRs                  &  $  -  - #  +  # #           # "  6 #     # #  %  , "     , % '  $ "   -