numpy.char.array#
- char.array(obj,itemsize=None,copy=True,unicode=None,order=None)[source]#
Create a
chararray.Note
This class is provided for numarray backward-compatibility.New code (not concerned with numarray compatibility) should usearrays of type
bytes_orstr_and use the free functionsinnumpy.charfor fast vectorized string operations instead.Versus a NumPy array of dtype
bytes_orstr_, thisclass adds the following functionality:values automatically have whitespace removed from the endwhen indexed
comparison operators automatically remove whitespace from theend when comparing values
vectorized string operations are provided as methods(e.g.
chararray.endswith)and infix operators (e.g.+,*,%)
- Parameters:
- objarray of str or unicode-like
- itemsizeint, optional
itemsize is the number of characters per scalar in theresulting array. Ifitemsize is None, andobj is anobject array or a Python list, theitemsize will beautomatically determined. Ifitemsize is provided andobjis of type str or unicode, then theobj string will bechunked intoitemsize pieces.
- copybool, optional
If true (default), then the object is copied. Otherwise, a copywill only be made if
__array__returns a copy, if obj is anested sequence, or if a copy is needed to satisfy any of the otherrequirements (itemsize, unicode,order, etc.).- unicodebool, optional
When true, the resulting
chararraycan contain Unicodecharacters, when false only 8-bit characters. If unicode isNone andobj is one of the following:then the unicode setting of the output array will beautomatically determined.
- order{‘C’, ‘F’, ‘A’}, optional
Specify the order of the array. If order is ‘C’ (default), then thearray will be in C-contiguous order (last-index varies thefastest). If order is ‘F’, then the returned arraywill be in Fortran-contiguous order (first-index varies thefastest). If order is ‘A’, then the returned array maybe in any order (either C-, Fortran-contiguous, or evendiscontiguous).
Examples
>>>importnumpyasnp>>>char_array=np.char.array(['hello','world','numpy','array'])>>>char_arraychararray(['hello', 'world', 'numpy', 'array'], dtype='<U5')