관리-도구
편집 파일: defchararray.cpython-37.pyc
B ��FdA � 4 @ s d Z ddlmZmZmZ ddlZddlmZmZm Z m Z mZmZ ddl mZmZ ddl mZ ddlmZ dd lmZmZ ddlZd ddd ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=g4Zdaejd d>k�r eZeZneZeZe Z!d?d@� Z"dAdB� Z#dCdD� Z$dEdF� Z%dGd� Z&dHd� Z'dId � Z(dJd� Z)dKd� Z*dLd� Z+dMd� Z,dNd� Z-dOd� Z.dPd� Z/dQd� Z0d~dSd�Z1ddTd�Z2d�dUd�Z3d�dVd�Z4d�dWd�Z5d�dYd�Z6d�dZd�Z7d�d[d�Z8d\d� Z9d]d� Z:d^d � Z;d_d!� Z<d`d"� Z=dad#� Z>dbd$� Z?dcd%� Z@d�ddd&�ZAded'� ZBd�dfd(�ZCdgd)� ZDd�dhd*�ZEd�did+�ZFd�djd,�ZGd�dkd-�ZHdld.� ZId�dmd/�ZJd�dnd0�ZKd�dod1�ZLd�dpd2�ZMd�dqd3�ZNd�drd4�ZOdsd5� ZPdtd6� ZQd�dud7�ZRdvd8� ZSdwd9� ZTdxd:� ZUdyd;� ZVG dzd � d e�ZWd�d|d<�Zd�d}d=�ZXdS )�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`. � )�division�absolute_import�print_functionN� )�string_�unicode_�integer�object_�bool_� character)�ndarray�compare_chararrays)�array)�_vec_string)�asbytes�long� chararray�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 �asarray� c 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�_unicode� issubclass�numpyrD �dtype�typer r )�args�x� rN �J/opt/alt/python37/lib64/python3.7/site-packages/numpy/core/defchararray.py�_use_unicode2 s rP 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. )rI rD �tolist)�resultrN rN rO �_to_string_or_unicode_array@ s rS 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)rL ZnewargsZchkrN rN rO �_clean_argsG s rU 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. � )rH rJ rK r �itemsize)�arN rN rO �_get_num_charsW s rY c C s t | |dd�S )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==T)r )�x1�x2rN rN rO r b s c C s t | |dd�S )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!=T)r )rZ r[ rN rN rO r z s c C s t | |dd�S )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>=T)r )rZ r[ rN rN rO r � s c C s t | |dd�S )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<=T)r )rZ r[ rN rN rO r � s c C s t | |dd�S )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 �>T)r )rZ r[ rN rN rO r � s c C s t | |dd�S )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 �<T)r )rZ r[ rN rN rO r � s 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 -------- __builtin__.len �__len__)r r )rX rN rN rO 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__)rI rD rY rP r )rZ r[ Zarr1Zarr2�out_sizerJ rN rN rO r s 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__)rI rD rH rJ rK r � ValueErrorrY �maxr r )rX �i�a_arrZi_arrr` rN rN rO r s c C s t t| td|f��S )a� Return (a % i), that is pre-Python 2.6 string formatting (iterpolation), 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__)rS r r )rX �valuesrN rN rO 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 )rI rD r rJ )rX re rN rN rO r V s " � 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 )rI rD r rc �flat� issubdtyperJ r r r rK )rX �width�fillcharre � width_arr�sizerN rN rO r | s 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='|S7') >>> 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 rU )rX �sub�start�endrN rN rO r � s +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='|S7') >>> 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 )rS r r rU )rX �encoding�errorsrN rN rO 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! )rS r r rU )rX rr rs rN rN rO r! � s c C s t | td||gt|� �S )aU 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='|S3') >>> np.char.endswith(s, 'ar') array([False, True], dtype=bool) >>> np.char.endswith(s, 'a', start=1, end=2) array([False, True], dtype=bool) r"