File: //lib/python3/dist-packages/numpy/core/__pycache__/defchararray.cpython-310.pyc
o
6��ag � @ s� d Z ddlZddlZddlmZmZmZmZmZm Z m
Z
ddlmZm
Z
ddlmZ ddlmZ ddlmZ dd lmZ dd
lmZ ddlZg d�Zdaejejdd
�Zdd� Zdd� Zdd� Zdd� Z dd� Z!ee!�dd� �Z"ee!�dd� �Z#ee!�dd� �Z$ee!�dd� �Z%ee!�d d!� �Z&ee!�d"d#� �Z'd$d%� Z(ee(�d&d'� �Z)ee!�d(d)� �Z*d*d+� Z+ee+�d,d-� �Z,d.d/� Z-ee-�d0d1� �Z.ee(�d2d3� �Z/d�d4d5�Z0ee0�d�d7d8��Z1d�d9d:�Z2ee2�d�d;d<��Z3d�d=d>�Z4ee4�d�d?d@��Z5ee4�d�dAdB��Z6d�dCdD�Z7ee7�d�dEdF��Z8d�dGdH�Z9ee9�d�dJdK��Z:ee2�d�dLdM��Z;ee2�d�dNdO��Z<ee(�dPdQ� �Z=ee(�dRdS� �Z>ee(�dTdU� �Z?ee(�dVdW� �Z@ee(�dXdY� �ZAee(�dZd[� �ZBee(�d\d]� �ZCd^d_� ZDeeD�d`da� �ZEd�dbdc�ZFeeF�d�ddde��ZGee(�dfdg� �ZHd�dhdi�ZIeeI�d�djdk��ZJdldm� ZKeeK�dndo� �ZLd�dpdq�ZMeeM�d�drds��ZNee2�d�dtdu��ZOee2�d�dvdw��ZPeeF�d�dxdy��ZQeeK�dzd{� �ZRd�d|d}�ZSeeS�d�d~d��ZTd�d�di�ZIeeI�d�d�d���ZUeeS�d�d�d���ZVd�d�d��ZWeeW�d�d�d���ZXd�d�d��ZYeeY�d�d�d���ZZeeI�d�d�d���Z[ee(�d�d�� �Z\ee(�d�d�� �Z]d�d�d��Z^ee^�d�d�d���Z_ee(�d�d�� �Z`d�d�� Zaeea�d�d�� �Zbee(�d�d�� �Zcee(�d�d�� �Zded��G d�d�� d�e��Zed�d�d��Zd�d�d��ZfdS )�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`.
� N� )�string_�unicode_�integer�int_�object_�bool_� character)�ndarray�compare_chararrays��array)�_vec_string)�
set_module)� overrides)�asbytes)3�equal� not_equal�
greater_equal�
less_equal�greater�less�str_len�add�multiply�mod�
capitalize�center�count�decode�encode�endswith�
expandtabs�find�index�isalnum�isalpha�isdigit�islower�isspace�istitle�isupper�join�ljust�lower�lstrip� partition�replace�rfind�rindex�rjust�
rpartition�rsplit�rstrip�split�
splitlines�
startswith�strip�swapcase�title� translate�upper�zfill� isnumeric� isdecimalr
�asarrayz
numpy.char)�modulec G s4 | D ]}t |t�stt�|�jjt�rt S qtS )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�str�
issubclass�numpyrC �dtype�typer r )�args�x� rM �9/usr/lib/python3/dist-packages/numpy/core/defchararray.py�_use_unicode1 s
��rO c C s t �| �� �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.
)rH rC �tolist)�resultrM rM rN �_to_string_or_unicode_array? s rR c G s* g }| D ]}|du r
|S |� |� 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)rK �newargs�chkrM rM rN �_clean_argsF s �rV c C s t | jjt�r| jd S | 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.
� )rG rI rJ r �itemsize��arM rM rN �_get_num_charsV s
r[ c C � | |fS �NrM ��x1�x2rM rM rN �_binary_op_dispatchera � ra c C � t | |dd�S )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==T�r r^ rM rM rN r e � r c C rc )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!=Trd r^ rM rM rN r re r c C rc )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>=Trd r^ rM rM rN r � s r c C rc )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<=Trd r^ rM rM rN r � re r c C rc )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
�>Trd r^ rM rM rN r � re r c C rc )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
�<Trd r^ rM rM rN r � re r c C � | fS r] rM rY rM rM rN �_unary_op_dispatcher � ri c C � t | td�S )z�
Return len(a) element-wise.
Parameters
----------
a : array_like of str or unicode
Returns
-------
out : ndarray
Output array of integers
See Also
--------
builtins.len
�__len__)r r rY rM rM rN r s r c C sB t �| �}t �|�}t|�t|� }t||�}t|||fd|f�S )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 `string_` or `unicode_`, depending on input types
of the same shape as `x1` and `x2`.
�__add__)rH rC r[ rO r )r_ r` �arr1�arr2�out_sizerI rM rM rN r s
r c C rh r] rM )rZ �irM rM rN �_multiply_dispatcher: rj rr c C s\ t �| �}t �|�}t|jjt�std��t|�tt |�� �d� }t
||jj|fd|f�S )av
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
zCan only multiply by integersr �__mul__)rH rC rG rI rJ r �
ValueErrorr[ �max�intr )rZ rq �a_arr�i_arrrp rM rM rN r > s
�r c C r\ r] rM �rZ �valuesrM rM rN �_mod_dispatcher\ rb r{ c C � t t| td|f��S )a�
Return (a % i), that is pre-Python 2.6 string formatting
(interpolation), element-wise for a pair of array_likes of str
or unicode.
Parameters
----------
a : array_like of str or unicode
values : array_like of values
These values will be element-wise interpolated into the string.
Returns
-------
out : ndarray
Output array of str or unicode, depending on input types
See Also
--------
str.__mod__
�__mod__�rR r r ry rM rM rN r ` s �r c C � t �| �}t||jd�S )a�
Return a copy of `a` with only the first character of each element
capitalized.
Calls `str.capitalize` element-wise.
For 8-bit strings, this method is locale-dependent.
Parameters
----------
a : array_like of str or unicode
Input array of strings to capitalize.
Returns
-------
out : ndarray
Output array of str or unicode, depending on input
types
See Also
--------
str.capitalize
Examples
--------
>>> 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')
r �rH rC r rI �rZ rw rM rM rN r | s
#r c C rh r] rM �rZ �width�fillcharrM rM rN �_center_dispatcher� rj r� � c C �V t �| �}t �|�}tt �|j��}t �|jt j�rt|�}t ||jj
|fd||f�S )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
r �rH rC rv ru �flat�
issubdtyperI r r r rJ �rZ r� r� rw � width_arr�sizerM rM rN r � s
�r c C rh r] rM �rZ �sub�start�endrM rM rN �_count_dispatcher� rj r� c C � t | td||gt|� �S )a�
Returns an array with the number of non-overlapping occurrences of
substring `sub` in the range [`start`, `end`].
Calls `str.count` element-wise.
Parameters
----------
a : array_like of str or unicode
sub : str or unicode
The substring to search for.
start, end : int, optional
Optional arguments `start` and `end` are interpreted as slice
notation to specify the range in which to count.
Returns
-------
out : ndarray
Output array of ints.
See Also
--------
str.count
Examples
--------
>>> c = np.array(['aAaAaA', ' aA ', 'abBABba'])
>>> c
array(['aAaAaA', ' aA ', 'abBABba'], dtype='<U7')
>>> 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 �r r rV r� rM rM rN r � s +r c C rh r] rM �rZ �encoding�errorsrM rM rN �_code_dispatcher� rj r� c C � t t| 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='<U7')
>>> 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 �rR r r rV r� rM rM rN r s *�r c C r� )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 r� r� rM rM rN r 0 s �r c C rh r] rM �rZ �suffixr� r� rM rM rN �_endswith_dispatcherT rj r� c C r� )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='<U3')
>>> np.char.endswith(s, 'ar')
array([False, True])
>>> np.char.endswith(s, 'a', start=1, end=2)
array([False, True])
r! �r r rV r� rM rM rN r! X s (�r! c C rh r] rM �rZ �tabsizerM rM rN �_expandtabs_dispatcher� rj r� � c C r| )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"