Файловый менеджер - Редактировать - /home/digitalm/venv/lib/python3.7/site-packages/numpy/core/__pycache__/defchararray.cpython-37.pyc
Назад
B �5�gg � 3 @ sN d Z ddlZddlZddlmZmZmZmZmZm Z m Z ddlmZm Z ddlmZ ddlmZ ddlmZ dd lmZ dd lmZ ddlZddd ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=g3Zdaejejd>d?�Zd@dA� ZdBdC� ZdDdE� ZdFdG� Z dHdI� Z!ee!�dJd� �Z"ee!�dKd� �Z#ee!�dLd � �Z$ee!�dMd� �Z%ee!�dNd� �Z&ee!�dOd� �Z'dPdQ� Z(ee(�dRd� �Z)ee!�dSd� �Z*dTdU� Z+ee+�dVd� �Z,dWdX� Z-ee-�dYd� �Z.ee(�dZd� �Z/d�d[d\�Z0ee0�d�d^d��Z1d�d_d`�Z2ee2�d�dad��Z3d�dbdc�Z4ee4�d�ddd��Z5ee4�d�ded��Z6d�dfdg�Z7ee7�d�dhd��Z8d�didj�Z9ee9�d�dld��Z:ee2�d�dmd��Z;ee2�d�dnd��Z<ee(�dod� �Z=ee(�dpd� �Z>ee(�dqd � �Z?ee(�drd!� �Z@ee(�dsd"� �ZAee(�dtd#� �ZBee(�dud$� �ZCdvdw� ZDeeD�dxd%� �ZEd�dydz�ZFeeF�d�d{d&��ZGee(�d|d'� �ZHd�d}d~�ZIeeI�d�dd(��ZJd�d�� ZKeeK�d�d)� �ZLd�d�d��ZMeeM�d�d�d*��ZNee2�d�d�d+��ZOee2�d�d�d,��ZPeeF�d�d�d-��ZQeeK�d�d.� �ZRd�d�d��ZSeeS�d�d�d/��ZTd�d�d~�ZIeeI�d�d�d0��ZUeeS�d�d�d1��ZVd�d�d��ZWeeW�d�d�d2��ZXd�d�d��ZYeeY�d�d�d3��ZZeeI�d�d�d4��Z[ee(�d�d5� �Z\ee(�d�d6� �Z]d�d�d��Z^ee^�d�d�d7��Z_ee(�d�d8� �Z`d�d�� Zaeea�d�d9� �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�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 x.| D ]&}t |t�s(tt�|�jjt�rtS qW tS )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�numpyrB �dtype�typer r )�args�x� rL �M/home/digitalm-up/venv/lib/python3.7/site-packages/numpy/core/defchararray.py�_use_unicode1 s rN 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. )rG rB �tolist)�resultrL rL rM �_to_string_or_unicode_array? s rQ c G s* g }x | D ]}|dkrP |� |� q W |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)rJ ZnewargsZchkrL rL rM �_clean_argsF s rS 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. � )rF rH rI r �itemsize)�arL rL rM �_get_num_charsV s rW c C s | |fS )NrL )�x1�x2rL rL rM �_binary_op_dispatchera s rZ c C s 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 )rX rY rL rL rM r e s c C s t | |dd�S )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!=T)r )rX rY rL rL rM r s c C s t | |dd�S )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>=T)r )rX rY rL rL rM r � s c C s t | |dd�S )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<=T)r )rX rY rL rL rM r � s c C s t | |dd�S )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 �>T)r )rX rY rL rL rM r � s c C s t | |dd�S )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 �<T)r )rX rY rL rL rM r � s c C s | fS )NrL )rV rL rL rM �_unary_op_dispatcher s r] c C s 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 )rV rL rL rM r s 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__)rG rB rW rN r )rX rY Zarr1Zarr2�out_sizerH rL rL rM r s c C s | fS )NrL )rV �irL rL rM �_multiply_dispatcher: s rb c C s\ t �| �}t �|�}t|jjt�s*td��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__)rG rB rF rH rI r � ValueErrorrW �max�intr )rV ra �a_arrZi_arrr` rL rL rM r > s c C s | |fS )NrL )rV �valuesrL rL rM �_mod_dispatcher\ s ri c C s 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__)rQ r r )rV rh rL rL rM r ` s c C s 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 )rG rB r rH )rV rg rL rL rM r | s # c C s | fS )NrL )rV �width�fillcharrL rL rM �_center_dispatcher� s rm � c C sV t �| �}t �|�}tt �|j��}t �|jt j�r<t|�}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 )rG rB rf re �flat� issubdtyperH r r r rI )rV rk rl rg � width_arr�sizerL rL rM r � s c C s | fS )NrL )rV �sub�start�endrL rL rM �_count_dispatcher� s rv c C s 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 rS )rV rs rt ru rL rL rM r � s +c C s | fS )NrL )rV �encoding�errorsrL rL rM �_code_dispatcher� s ry c C s 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 )rQ r r rS )rV rw rx rL rL rM r s *c C s t t| 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 )rQ r r rS )rV rw rx rL rL rM r 0 s c C s | fS )NrL )rV �suffixrt ru rL rL rM �_endswith_dispatcherT s r{ c C s t | 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='<U3') >>> np.char.endswith(s, 'ar') array([False, True]) >>> np.char.endswith(s, 'a', start=1, end=2) array([False, True]) r )r r rS )rV rz rt ru rL rL rM r X s (c C s | fS )NrL )rV �tabsizerL rL rM �_expandtabs_dispatcher� s r} � c C s t t| 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! )rQ r r )rV r| rL rL rM r! � s c C s t | 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"