numpy 1.22.4 Pypi GitHub Homepage
Other Docs
MethodsParametersBackRef
chararray(shape, itemsize=1, unicode=False, buffer=None, offset=0, strides=None, order=None)
note

The :None:None:`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 :None:None:`dtype` :None:None:`object_`, :None:None:`string_` or :None:None:`unicode_`, and use the free functions in the :None:None:`numpy.char` module for fast vectorized string operations.

Versus a regular NumPy array of type :None:None:`str` or :None:None:`unicode`, this class adds the following functionality:

  1. values automatically have whitespace removed from the end when indexed

  2. comparison operators automatically remove whitespace from the end when comparing values

  3. vectorized string operations are provided as methods (e.g. :None:None:`.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 :None:None:`buffer` (with :None:None:`offset` and :None:None:`strides`) if it is not None . If :None:None:`buffer` is None , then constructs a new array with :None:None:`strides` in "C order", unless both len(shape) >= 2 and order='F' , in which case :None:None:`strides` is in "Fortran order".

Methods

Parameters

shape : tuple

Shape of the array.

itemsize : int, optional

Length of each array element, in number of characters. Default is 1.

unicode : bool, optional

Are the array elements of type unicode (True) or string (False). Default is False.

buffer : object exposing the buffer interface or str, optional

Memory address of the start of the array data. Default is None, in which case a new array is created.

offset : int, optional

Fixed stride displacement from the beginning of an axis? Default is 0. Needs to be >=0.

strides : array_like of ints, optional

Strides for the array (see :None:None:`ndarray.strides` for full description). Default is None.

order : {'C', 'F'}, optional

The order in which the array data is stored in memory: 'C' -> "row major" order (the default), 'F' -> "column major" (Fortran) order.

Provides a convenient view on arrays of string and unicode values.

Examples

>>> charar = np.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.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')
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

numpy.char.array numpy.char.asarray

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /numpy/__init__.py#None
type: <class 'type'>
Commit: