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_, bytes_ or str_, and use the free functions in the numpy.char module for fast vectorized string operations.
Versus a NumPy array of dtype bytes_ or str_, this class adds the following functionality:
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”.
Shape of the array.
Length of each array element, in number of characters. Default is 1.
Are the array elements of type unicode (True) or string (False). Default is False.
Memory address of the start of the array data. Default is None, in which case a new array is created.
Fixed stride displacement from the beginning of an axis? Default is 0. Needs to be >=0.
Strides for the array (see strides for full description). Default is None.
The order in which the array data is stored in memory: ‘C’ -> “row major” order (the default), ‘F’ -> “column major” (Fortran) order.
>>> import numpy as np
>>> charar = np.char.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.char.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')
TView of the transposed array.
baseBase object if memory is from some other object.
ctypesAn object to simplify the interaction of the array with the ctypes module.
dataPython buffer object pointing to the start of the array’s data.
dtypeData-type of the array’s elements.
flagsInformation about the memory layout of the array.
flatA 1-D iterator over the array.
imagThe imaginary part of the array.
itemsizeLength of one array element in bytes.
mTView of the matrix transposed array.
nbytesTotal bytes consumed by the elements of the array.
ndimNumber of array dimensions.
realThe real part of the array.
shapeTuple of array dimensions.
sizeNumber of elements in the array.
stridesTuple of bytes to step in each dimension when traversing an array.
| Copy of the array, cast to a specified type. |
| Returns the indices that would sort this array. |
| Return a copy of the array. |
| Returns an array with the number of non-overlapping occurrences of substring |
| Calls |
| Dump a pickle of the array to the specified file. |
| Returns the pickle of the array as a string. |
| Calls |
| Returns a boolean array which is |
| Return a copy of each string element where all tab characters are replaced by one or more spaces. |
| Fill the array with a scalar value. |
| For each element, return the lowest index in the string where substring |
| Return a copy of the array collapsed into one dimension. |
| Returns a field of the given array as a certain type. |
| Like |
| Returns true for each element if all characters in the string are alphanumeric and there is at least one character, false otherwise. |
| Returns true for each element if all characters in the string are alphabetic and there is at least one character, false otherwise. |
For each element in | |
| Returns true for each element if all characters in the string are digits and there is at least one character, false otherwise. |
| Returns true for each element if all cased characters in the string are lowercase and there is at least one cased character, false otherwise. |
For each element in | |
| Returns true for each element if there are only whitespace characters in the string and there is at least one character, false otherwise. |
| Returns true for each element if the element is a titlecased string and there is at least one character, false otherwise. |
| Returns true for each element if all cased characters in the string are uppercase and there is at least one character, false otherwise. |
| Copy an element of an array to a standard Python scalar and return it. |
| Return a string which is the concatenation of the strings in the sequence |
| Return an array with the elements of |
| Return an array with the elements of |
| For each element in |
| Return the indices of the elements that are non-zero. |
| Set |
| Return a flattened array. |
| Repeat elements of an array. |
| For each element in |
| Returns an array containing the same data with a new shape. |
| Change shape and size of array in-place. |
| For each element in |
| Like |
| Return an array with the elements of |
| For each element in |
| For each element in |
| Find indices where elements of |
| Put a value into a specified place in a field defined by a data-type. |
| Set array flags WRITEABLE, ALIGNED, WRITEBACKIFCOPY, respectively. |
| Sort an array in-place. |
| For each element in |
| For each element in |
| Remove axes of length one from |
| Returns a boolean array which is |
| For each element in |
| Return a view of the array with |
| For each element in |
| Return an array formed from the elements of |
| For each element in |
| Write array to a file as text or binary (default). |
| Return the array as an |
| For each element in |
| Returns a view of the array with axes transposed. |
| Return an array with the elements of |
| New view of array with the same data. |
| Return the numeric string left-filled with zeros in a string of length |
© 2005–2024 NumPy Developers
Licensed under the 3-clause BSD License.
https://numpy.org/doc/2.4/reference/generated/numpy.char.chararray.html