{ } Raw JSON

bundles / numpy 2.4.4 / numpy / char / chararray

class

numpy.char:chararray

source: /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 : 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 ~numpy.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.

Methods

astype
argsort
copy
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
put
ravel
repeat
replace
reshape
resize
rfind
rindex
rjust
rsplit
rstrip
searchsorted
setfield
setflags
sort
split
splitlines
squeeze
startswith
strip
swapaxes
swapcase
take
title
tofile
tolist
translate
transpose
upper
view
zfill

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

Referenced by