bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / char / chararray
class
numpy.char:chararray
source: build-install/usr/lib/python3.14/site-packages/numpy/char/__init__.py
Signature
class chararray ( shape , itemsize = 1 , unicode = False , buffer = None , offset = 0 , strides = None , order = None ) Summary
Provides a convenient view on arrays of string and unicode values.
Extended Summary
Versus a NumPy array of dtype bytes_ or str_, this class adds the following functionality:
values automatically have whitespace removed from the end when indexed
comparison operators automatically remove whitespace from the end when comparing values
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".
Parameters
shape: tupleShape of the array.
itemsize: int, optionalLength of each array element, in number of characters. Default is 1.
unicode: bool, optionalAre the array elements of type unicode (True) or string (False). Default is False.
buffer: object exposing the buffer interface or str, optionalMemory address of the start of the array data. Default is None, in which case a new array is created.
offset: int, optionalFixed stride displacement from the beginning of an axis? Default is 0. Needs to be >=0.
strides: array_like of ints, optionalStrides for the array (see
~numpy.ndarray.stridesfor full description). Default is None.order: {'C', 'F'}, optionalThe order in which the array data is stored in memory: 'C' -> "row major" order (the default), 'F' -> "column major" (Fortran) order.
Methods
astypeargsortcopycountdecodedumpdumpsencodeendswithexpandtabsfillfindflattengetfieldindexisalnumisalphaisdecimalisdigitislowerisnumericisspaceistitleisupperitemjoinljustlowerlstripnonzeroputravelrepeatreplacereshaperesizerfindrindexrjustrsplitrstripsearchsortedsetfieldsetflagssortsplitsplitlinessqueezestartswithstripswapaxesswapcasetaketitletofiletolisttranslatetransposeupperviewzfill
Examples
import numpy as np charar = np.char.chararray((3, 3)) charar[:] = 'a' charar✓
charar = np.char.chararray(charar.shape, itemsize=5) charar[:] = 'abc' charar✓
Aliases
-
numpy.char.chararray