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_, string_ or unicode_, and use the free functions in the numpy.char module for fast vectorized string operations.
Versus a regular Numpy array of type str or unicode, 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='Fortran', in which case strides is in “Fortran order”.
Parameters : | shape : tuple
itemsize : int, optional
unicode : bool, optional
buffer : int, optional
offset : int, optional
strides : array_like of ints, optional
order : {‘C’, ‘F’}, optional
|
---|
Examples
>>> charar = np.chararray((3, 3))
>>> charar[:] = 'a'
>>> charar
chararray([['a', 'a', 'a'],
['a', 'a', 'a'],
['a', 'a', 'a']],
dtype='|S1')
>>> charar = np.chararray(charar.shape, itemsize=5)
>>> charar[:] = 'abc'
>>> charar
chararray([['abc', 'abc', 'abc'],
['abc', 'abc', 'abc'],
['abc', 'abc', 'abc']],
dtype='|S5')
Methods
astype | |
argsort(a[, axis, kind, order]) | Returns the indices that would sort an array. |
copy(a) | Return an array copy of the given object. |
count | |
decode | |
dump | |
dumps | |
encode | |
endswith | |
expandtabs | |
fill | |
find | |
flatten | |
getfield | |
index | |
isalnum | |
isalpha | |
isdecimal | |
isdigit | |
islower | |
isnumeric | |
isspace | |
istitle | |
isupper | |
item | |
join | |
ljust | |
lower | |
lstrip | |
nonzero(a) | Return the indices of the elements that are non-zero. |
put(a, ind, v[, mode]) | Replaces specified elements of an array with given values. |
ravel(a[, order]) | Return a flattened array. |
repeat(a, repeats[, axis]) | Repeat elements of an array. |
replace | |
reshape(a, newshape[, order]) | Gives a new shape to an array without changing its data. |
resize(a, new_shape) | Return a new array with the specified shape. |
rfind | |
rindex | |
rjust | |
rsplit | |
rstrip | |
searchsorted(a, v[, side]) | Find indices where elements should be inserted to maintain order. |
setfield | |
setflags | |
sort(a[, axis, kind, order]) | Return a sorted copy of an array. |
split(ary, indices_or_sections[, axis]) | Split an array into multiple sub-arrays of equal size. |
splitlines | |
squeeze(a) | Remove single-dimensional entries from the shape of an array. |
startswith | |
strip | |
swapaxes(a, axis1, axis2) | Interchange two axes of an array. |
swapcase | |
take(a, indices[, axis, out, mode]) | Take elements from an array along an axis. |
title | |
tofile | |
tolist | |
tostring | |
translate | |
transpose(a[, axes]) | Permute the dimensions of an array. |
upper | |
view | |
zfill |