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:
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”.
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.
Examples
>>> 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')
T
View of the transposed array.
base
Base object if memory is from some other object.
ctypes
An object to simplify the interaction of the array with the ctypes module.
data
Python buffer object pointing to the start of the array’s data.
dtype
Data-type of the array’s elements.
flags
Information about the memory layout of the array.
flat
A 1-D iterator over the array.
imag
The imaginary part of the array.
itemsize
Length of one array element in bytes.
mT
View of the matrix transposed array.
nbytes
Total bytes consumed by the elements of the array.
ndim
Number of array dimensions.
real
The real part of the array.
shape
Tuple of array dimensions.
size
Number of elements in the array.
strides
Tuple of bytes to step in each dimension when traversing an array.
Methods
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4