Table of Contents

Class CharModule

Namespace
NumSharp
Assembly
NumSharp.dll

The numpy.char module surface, reachable as char: NumPy's legacy vectorized string operations. Its own functions are the comparisons that strip trailing whitespace (equal(object, object), not_equal(object, object), less(object, object), less_equal(object, object), greater(object, object), greater_equal(object, object), compare_chararrays(object, object, object, bool)), multiply(object, object) (its ValueError rule), partition(object, object) / rpartition(object, object) (the three parts stacked on a new last axis), the object path (split(object, object, object), rsplit(object, object, object), splitlines(object, object), join(object, object)) and the chararray constructors (chararray(Shape, long, bool, object, long, long[], char), array(object, long?, bool, bool?, char?), asarray(object, long?, bool?, char?)); the others ARE np.strings' functions (NumPy re-exports the same function objects), so they answer exactly as np.strings does, over S, U and StringDType text.

[ModuleName("np.char")]
public sealed class CharModule
Inheritance
CharModule
Inherited Members

Remarks

Arguments are array_likes (object), read as Python objects. An NDArray is used as it is; a C# string is NumPy's str (a 0-d U array); a byte[] is NumPy's bytes (a 0-d S array) and a byte[][] / any IEnumerable<byte[]> a list of bytes (an S array); a string[] or an object[] of text is a list of str; a C# number or bool is NumPy's Python scalar. Unlike np.strings (whose byte[] is a uint8 array, the general NDArray conversion), a byte[] here is text, because text is all these parameters can mean.

Python's NotImplemented is null. NumPy's comparisons answer NotImplemented for an S operand against a U one (the class check of _umath_strings_richcompare); the C# functions return null there.

Python's None has no array form. NumPy reads None as an object array; NumSharp has no object dtype, so a null array argument is an ArgumentNullException where NumPy raises its no-string / no-loop error. The object path (split(object, object, object), rsplit(object, object, object), splitlines(object, object), join(object, object)) is the exception: it models NumPy's object arrays, so there a null argument IS Python's None — NumPy's string operation on non-string array as the text argument, can only join an iterable as join's sequence, whitespace as split's separator.

The Char dtype. The module converts implicitly to the Char dtype descriptor (implicit operator DType(CharModule)), the meaning np.@char had before the module existed.

Methods

ToString()

Python's repr() of the module object.

public override string ToString()

Returns

string

<module 'numpy.char'>.

add(object, object, NDArray, NDArray, DType)

NumPy's np.char.add(x1, x2): element-wise string concatenation. In NumPy 2.4.2 it IS the np.add ufunc (np.char.add is np.strings.add is np.add), so two strings of one class concatenate at width width(x1) + width(x2) with every rule of add(NDArray, NDArray, NDArray, NDArray, DType).

public NDArray add(object x1, object x2, NDArray @out = null, NDArray where = null, DType dtype = null)

Parameters

x1 object

The first operand (an array or a text array_like; see the class remarks).

x2 object

The second operand.

out NDArray

An output to write into and return, or null.

where NDArray

A bool mask: only elements where it is True are computed, or null.

dtype DType

NumPy's dtype= (the string add promoter ignores it for two strings of one class).

Returns

NDArray

The concatenation, or out.

Remarks

A NEP 55 StringDType operand computes through np.add's StringDType loop (with a StringDType or U partner; NumPy's NA rules and its incompatible-NA TypeError apply).

Exceptions

ArgumentNullException

An operand is null.

TypeError

A bytes / str mix (ufunc 'add' cannot use operands with types …), a string and a number (NumPy's no-loop text), or a result wider than 2^31 - 1 bytes.

ArgumentException

out cannot receive the result, or the operands do not broadcast with out / where.

IncorrectShapeException

The two operands do not broadcast.

array(object, long?, bool, bool?, char?)

NumPy's np.char.array(obj, itemsize=None, copy=True, unicode=None, order=None): a chararray from a string, bytes, a list of them, a string array or a number array (whose numbers become their text).

public NDCharArray array(object obj, long? itemsize = null, bool copy = true, bool? unicode = null, char? order = null)

Parameters

obj object

What to convert (see the class remarks for the C# argument map): a string — itemsize defaults to its length and every element is set to the WHOLE string (array("abcdef", itemsize: 2) is ['ab', 'ab', 'ab'], NumPy's behaviour, not its documentation's chunks); a byte[] — chunked into itemsize-byte elements, a READ-ONLY view of the bytes; an S / U NDArray — viewed, or copied (see copy); any other array — its elements as their text, the longest one setting the width (a float32 / float16 by the double's repr, 0.10000000149011612; an empty axis ends the shape as tolist() does: (0, 3) gives (0,)); a list, a number, a bool or null (None) — through np.asarray / its text.

itemsize long?

The element width in characters, or null to discover it. 0 is NumPy's unsized request (a string array keeps its width, a number array casts at the dtype's fixed width).

copy bool

false shares the memory of an S array (a U array is always copied: NumPy compares the itemsize in characters with the array's in BYTES) and returns a chararray argument ITSELF.

unicode bool?

true for U, false for S, null to follow the input (a number array then becomes S). An S array with unicode: true and copy: false stays S, as in NumPy.

order char?

'C', 'F', 'A' or 'K' (either case), or null.

Returns

NDCharArray

The chararray. NumPy 2.4.2 returns a PLAIN ndarray when order is given for a string array (its np.asarray step drops the subclass); the C# result is a chararray with NumPy's data, layout and flags.

Remarks

Exceptions

DivideByZeroException

A string or bytes obj with an itemsize of 0 (its own length 0 included): NumPy's len(obj) // itemsize raises ZeroDivisionError (integer division or modulo by zero).

ValueError

A negative or too large itemsize (invalid itemsize in generic type tuple), an unknown order, or a ragged list (NumPy's inhomogeneous-shape text).

UnicodeEncodeError

Non-ASCII text into S.

UnicodeDecodeError

Non-ASCII bytes into U.

TypeError

A byte[] with unicode: true holds fewer bytes than the U elements need (buffer is too small for requested array).

NotSupportedException

A string chararray of width 0 would result, or an element NumPy converts as an object (an object array input).

asarray(object, long?, bool?, char?)

NumPy's np.char.asarray(obj, itemsize=None, unicode=None, order=None): array(object, long?, bool, bool?, char?) with copy: false — an S array is shared (a chararray argument is returned ITSELF), a U array is still copied (NumPy's itemsize comparison of characters with bytes).

public NDCharArray asarray(object obj, long? itemsize = null, bool? unicode = null, char? order = null)

Parameters

obj object

What to convert (see array(object, long?, bool, bool?, char?)).

itemsize long?

The element width in characters, or null to discover it.

unicode bool?

true for U, false for S, null to follow the input.

order char?

'C', 'F', 'A' or 'K', or null.

Returns

NDCharArray

The chararray (see array(object, long?, bool, bool?, char?) for the order quirk).

Remarks

Exceptions

DivideByZeroException

A string or bytes obj with an itemsize of 0.

ValueError

A negative or too large itemsize, an unknown order, or a ragged list.

UnicodeEncodeError

Non-ASCII text into S.

UnicodeDecodeError

Non-ASCII bytes into U.

TypeError

A byte[] with unicode: true holds fewer bytes than the elements need.

NotSupportedException

A string chararray of width 0 would result.

capitalize(object)

NumPy's np.char.capitalize(a), which IS capitalize(NDArray): each element's first character in titlecase and the rest lowered (CPython 3.8+'s str.capitalize: 'džemal' becomes 'Džemal'); bytes.capitalize uppercases the first byte and lowers the other ASCII letters. The text is the stored one, a chararray's trailing whitespace included.

public NDArray capitalize(object a)

Parameters

a object

The strings: an S / U / StringDType array or a text array_like (see the class remarks: a byte[] is Python bytes).

Returns

NDArray

A fresh C-ordered PLAIN array of a's dtype (a chararray operand too: NumPy's np.asarray drops the class), 0-d for a scalar. An S / U result keeps the element width, so a mapping that grows is cut.

Exceptions

ArgumentNullException

a is null (see the class remarks).

TypeError

a is not text (string operation on non-string array); a StringDType NA whose NA object is not a str.

SystemError

A U element holding a code unit past U+10FFFF.

NotSupportedException

a has no NumSharp array form.

center(object, object, object)

NumPy's np.char.center(a, width, fillchar=' '), which IS center(NDArray, NDArray, NDArray): each element centered in a string of width characters, padded with fillchar. An element longer than the width is unchanged.

public NDArray center(object a, object width, object fillchar = null)

Parameters

a object

The strings: an S / U / StringDType array or a text array_like.

width object

The widths: an integer array or a C# integer, broadcast. A float, a bool or text is NumPy's TypeError.

fillchar object

The fill characters, each exactly one character long, broadcast; null is NumPy's default ' '. A str fill beside an S operand is cast to bytes (ASCII only), a bytes fill beside a U operand to text.

Returns

NDArray

A fresh array: a's class at the widest result width for S / U, laid out like a; a StringDType array for StringDType. A chararray a gives a chararray view of the result (NumPy's chararray.array_wrap).

Exceptions

ArgumentNullException

a or width is null.

TypeError

width is not an integer array (unsupported type float64 for operand 'width'); a fill that is not one character (The fill character must be exactly one character long); a non-text operand; no common dtype or no loop for the classes; a uint64 width (NumPy's data type 'U6.0' not understood).

ValueError

An empty broadcast (zero-size array to reduction operation maximum which has no identity); a StringDType NA its rule refuses; a chararray operand beside a StringDType one that NumPy's trivial loop copies into StringDType() (0-d, or 1-d with at most np.getbufsize() elements: Can only create a chararray from string data.; a larger one computes NumPy's plain result).

UnicodeEncodeError

A non-ASCII fill for an S operand.

IncorrectShapeException

The operands do not broadcast.

OverflowException

A StringDType result past sys.maxsize bytes.

chararray(Shape, long, bool, object, long, long[], char)

NumPy's np.char.chararray(shape, itemsize=1, unicode=False, buffer=None, offset=0, strides=None, order='C'): a new chararray of itemsize-character S (or U) elements. Without a buffer the memory is np.empty's (a U chararray reads empty strings, an S one holds whatever the allocator recycled).

public NDCharArray chararray(Shape shape, long itemsize = 1, bool unicode = false, object buffer = null, long offset = 0, long[] strides = null, char order = 'C')

Parameters

shape Shape

The dimensions (an int, a long[] or a tuple converts).

itemsize long

The element width in characters. NumPy's (dtype, itemsize) tuple accepts 0 to 2^31 - 1 for S and to 2^29 - 1 for U.

unicode bool

true for U (str), false for S (bytes).

buffer object

null for new memory. A C# string is NumPy's str FILLER: every element is set to it (truncated to the width; an S chararray encodes it ASCII), and offset / strides are ignored. Any other buffer is viewed without copying, exactly as ndarray(Shape, DType, object, long, long[], char) views it: a byte[] / Memory<byte> writable (NumPy's bytearray), a ReadOnlyMemory<byte> read-only (NumPy's bytes), an NDArray through its bytes.

offset long

The BYTE offset of the first element in buffer.

strides long[]

The BYTE strides over buffer, or null for order's.

order char

'C' or 'F' (either case; 'A' / 'K' are C).

Returns

NDCharArray

The new chararray: it owns its memory without a buffer or with a string filler, and views the buffer otherwise.

Remarks

Exceptions

ValueError

itemsize is negative or too large (invalid itemsize in generic type tuple), a negative dimension (negative dimensions are not allowed), or an unknown order.

NotSupportedException

itemsize is 0: NumPy builds a zero-width S0 / U0 array, which NumSharp's fixed-width string buffers cannot hold.

UnicodeEncodeError

A string filler with a non-ASCII character into an S chararray.

TypeError

A buffer that is too small (buffer is too small for requested array) or not a bytes-like object.

compare_chararrays(object, object, object, bool)

NumPy's np.char.compare_chararrays(a1, a2, cmp, rstrip): the element-wise comparison cmp of two string arrays of one class, each element first stripped of its trailing NULs and ASCII whitespace when rstrip is true.

public NDArray compare_chararrays(object a1, object a2, object cmp, bool rstrip)

Parameters

a1 object

The first operand (an S / U array or a text array_like; see the class remarks).

a2 object

The second operand, of the same class.

cmp object

The comparison, as NumPy's s# argument reads it: a string (Python's str, read as its UTF-8 bytes) or a byte[] (Python's bytes, "=="u8.ToArray()), whose bytes must be ==, !=, <, <=, > or >=.

rstrip bool

True to strip each element's trailing NULs and ASCII whitespace before comparing.

Returns

NDArray

The bool result of the broadcast shape (a 0-d array for two scalars), or null — NumPy's NotImplemented — for an S operand against a U one.

Remarks

One overload, NumPy's signature: NumPy's cmp is a str or a read-only bytes-like object, two cases of one object parameter. NumPy's order, all probed: cmp is checked first (so a bad cmp wins over operands that are not text or do not broadcast), then both operands must be S / U (a NEP 55 StringDType array is not), then a class mix answers NotImplemented (before the broadcast), then the broadcast.

Exceptions

TypeError

cmp is neither text nor bytes (a bytes-like object is required, not 'NoneType' for null, the Python type's name otherwise); or an operand is not S / U text (comparison of non-string arrays).

UnicodeEncodeError

cmp holds a lone surrogate, which UTF-8 cannot encode (CPython's 'utf-8' codec can't encode character '\ud800' in position 0: surrogates not allowed).

ValueError

cmp is not one of the six comparisons: comparison must be '==', '!=', '<', '>', '<=', '>='.

ArgumentNullException

An operand is null.

IncorrectShapeException

The operands do not broadcast.

count(object, object, object, object)

NumPy's np.char.count(a, sub, start=0, end=None), which IS count(NDArray, NDArray, NDArray, NDArray): the number of non-overlapping occurrences of sub in each element's a[start:end], counted greedily from the left; an empty substring occurs len + 1 times in the range.

public NDArray count(object a, object sub, object start = null, object end = null)

Parameters

a object

The searched strings: an S / U / StringDType array or a text array_like.

sub object

The substrings, broadcast: the same class as a (a U one beside a StringDType a, or the reverse, is cast to StringDType; a bytes one beside U or a number has no loop).

start object

The range starts in slice notation (negative counts from the end), any integer dtype, broadcast; null is NumPy's default 0.

end object

The range ends in slice notation, broadcast; null is NumPy's None (the whole string).

Returns

NDArray

A plain int64 array of the broadcast shape (0-d for scalar operands); a chararray operand still gives a plain array.

Exceptions

ArgumentNullException

a or sub is null.

TypeError

No loop for the operand classes (an S array with a str substring, a number substring: NumPy's no-loop text); two StringDType operands with different NA objects.

TypeError

start / end cannot reach int64 by a same_kind cast (a float or text: Cannot cast ufunc 'count' input 2 from dtype('float64') to dtype('int64') with casting rule 'same_kind').

OverflowException

A start / end literal past int64.

IncorrectShapeException

The operands do not broadcast.

ValueError

A StringDType NA whose NA object is not a string; a chararray operand beside a StringDType one that NumPy's trivial loop copies into StringDType() (0-d, or 1-d with at most np.getbufsize() elements: Can only create a chararray from string data.; a larger one computes NumPy's plain result).

decode(object, object, object)

NumPy's np.char.decode(a, encoding=None, errors=None), which IS decode(NDArray, object, object): CPython's bytes.decode(encoding, errors) per element of an S array, the results as a U array. An element is its bytes without the trailing NULs, a chararray's trailing whitespace included.

public NDArray decode(object a, object encoding = null, object errors = null)

Parameters

a object

The bytes: an S array or a bytes array_like (see the class remarks: a byte[] is Python bytes, a list of byte[] an S array).

encoding object

The codec name, or null for UTF-8 (the codecs of decode(NDArray, object, object)); broadcast against a.

errors object

The error handler, or null for strict ("ignore", "replace", "backslashreplace", "surrogateescape", "surrogatepass"; "xmlcharrefreplace" and "namereplace" are CPython's TypeError at the first error); ignored when encoding is null. Broadcast like encoding.

Returns

NDArray

A fresh C-ordered PLAIN U array over the broadcast shape (a chararray operand too), as wide as the longest decoding (at least 1), 0-d for a scalar; an empty U1 array when the broadcast is empty.

Exceptions

ArgumentNullException

a is null (see the class remarks).

AttributeError

a is U or StringDType: type object 'str' has no attribute 'decode'.

TypeError

a is not text; an argument that is not a str; xmlcharrefreplace / namereplace at an error (don't know how to handle UnicodeDecodeError in error callback).

ValueError

An argument holding a NUL; a ragged argument list.

UnicodeDecodeError

Bytes the codec cannot decode under strict, or a handler that re-raises it.

UnicodeEncodeError

A surrogate in an argument.

UnicodeError

The undefined codec over a non-empty element.

LookupError

An unknown or non-text codec; an unknown handler name at the first error.

IncorrectShapeException

The operands do not broadcast.

NotSupportedException

A Python codec NumSharp does not implement; an argument with no NumSharp array form.

encode(object, object, object)

NumPy's np.char.encode(a, encoding=None, errors=None), which IS encode(NDArray, object, object): CPython's str.encode(encoding, errors) per element of a U / StringDType array, the results as an S array. The text is the stored one, a chararray's trailing whitespace included.

public NDArray encode(object a, object encoding = null, object errors = null)

Parameters

a object

The text: a U / StringDType array or a text array_like (see the class remarks; a C# string is a 0-d U array).

encoding object

The codec name, or null for UTF-8 (the codecs and aliases of encode(NDArray, object, object)), converted as NumPy's np.asarray converts it and broadcast against a.

errors object

The error handler, or null for strict ("ignore", "replace", "backslashreplace", "xmlcharrefreplace", "namereplace", "surrogateescape", "surrogatepass"); ignored when encoding is null (NumPy's _clean_args stops at the first None). Broadcast like encoding.

Returns

NDArray

A fresh C-ordered PLAIN S array over the broadcast shape (a chararray operand too), as wide as the longest encoding (at least 1), 0-d for a scalar; an empty S1 array when the broadcast is empty.

Exceptions

ArgumentNullException

a is null (see the class remarks).

AttributeError

a is S: type object 'bytes' has no attribute 'encode'.

TypeError

a is not text (string operation on non-string array); a StringDType NA object that is not a str; an argument that is not a str (encode() argument 'encoding' must be str, not numpy.bytes_).

ValueError

An argument holding a NUL (embedded null character); a ragged argument list.

UnicodeEncodeError

A character the codec cannot encode under strict, a handler that re-raises it, or a surrogate in an argument.

UnicodeError

The undefined codec.

LookupError

An unknown or non-text codec (unknown encoding: nope); an unknown handler name at the first error.

SystemError

A U element of one unit past U+10FFFF.

IncorrectShapeException

The operands do not broadcast.

NotSupportedException

A Python codec NumSharp does not implement; an argument with no NumSharp array form.

endswith(object, object, object, object)

NumPy's np.char.endswith(a, suffix, start=0, end=None), which IS endswith(NDArray, NDArray, NDArray, NDArray): whether each element's a[start:end] ends with suffix.

public NDArray endswith(object a, object suffix, object start = null, object end = null)

Parameters

a object

The tested strings: an S / U / StringDType array or a text array_like.

suffix object

The suffixes, broadcast (the classes of count(object, object, object, object)).

start object

The range starts in slice notation, broadcast; null is NumPy's default 0.

end object

The range ends in slice notation, broadcast; null is NumPy's None.

Returns

NDArray

A plain bool array of the broadcast shape (0-d for scalar operands).

Exceptions

ArgumentNullException

a or suffix is null.

TypeError

No loop for the operand classes; two different StringDType NA objects.

TypeError

A start / end that cannot reach int64 by a same_kind cast.

OverflowException

A start / end literal past int64.

IncorrectShapeException

The operands do not broadcast.

ValueError

A StringDType NA whose NA object is neither a string nor NaN-like; a chararray operand beside a StringDType one that NumPy's trivial loop copies into StringDType() (0-d, or 1-d with at most np.getbufsize() elements: Can only create a chararray from string data.; a larger one computes NumPy's plain result).

equal(object, object)

NumPy's np.char.equal(x1, x2): x1 == x2 element-wise once each element has lost its trailing NULs and ASCII whitespace — compare_chararrays(x1, x2, '==', True). So 'a ' equals 'a', where np.equal says they differ.

public NDArray equal(object x1, object x2)

Parameters

x1 object

The first operand: an S / U array or a text array_like (see the class remarks).

x2 object

The second operand, of the same class.

Returns

NDArray

The bool result of the broadcast shape (a 0-d array for two scalars), or null — NumPy's NotImplemented — when one operand is S and the other U.

Remarks

The stripped units are NUL, ' ', '\t', '\n', '\v', '\f', '\r' for both classes (NumPy's NumPyOS_ascii_isspace); other whitespace such as '\xa0' or U+3000 stays, and a leading space stays. The result is laid out as NumPy's iterator allocates it (an F-ordered pair gives an F result).

Exceptions

ArgumentNullException

An operand is null (NumPy's None; see the class remarks).

TypeError

An operand is not S / U text — a number, a bool, a NEP 55 StringDType array: comparison of non-string arrays.

IncorrectShapeException

The operands do not broadcast (NumPy's ValueError text).

expandtabs(object, object)

NumPy's np.char.expandtabs(a, tabsize=8), which IS expandtabs(NDArray, NDArray): each tab replaced by spaces up to the next multiple of tabsize columns (the column restarts after '\n' and '\r'; a tab size of 0 or less removes the tabs).

public NDArray expandtabs(object a, object tabsize = null)

Parameters

a object

The strings: an S / U / StringDType array or a text array_like.

tabsize object

The tab sizes (any integer dtype), broadcast; null is NumPy's default 8.

Returns

NDArray

A fresh array (for S / U at the widest result width as NumPy sizes it: a tab's columns plus every other character's BYTES, so a U result is wider than its text).

Exceptions

ArgumentNullException

a is null.

TypeError

A non-text operand (NumPy's no-loop text).

TypeError

A tab size that cannot reach int64 by a same_kind cast (a float: Cannot cast ufunc '_expandtabs_length' input 1 from dtype('float64') to dtype('int64') with casting rule 'same_kind').

IncorrectShapeException

The operands do not broadcast.

OverflowException

An expanded string longer than 2^31 - 1 (new string is too long).

ValueError

An empty broadcast; a StringDType NA whose NA object is not a string.

find(object, object, object, object)

NumPy's np.char.find(a, sub, start=0, end=None), which IS find(NDArray, NDArray, NDArray, NDArray): for each element, the lowest index where sub occurs inside a[start:end], or -1. Indices are characters (code points for StringDType); trailing NULs never count.

public NDArray find(object a, object sub, object start = null, object end = null)

Parameters

a object

The searched strings: an S / U / StringDType array or a text array_like.

sub object

The substrings, broadcast (the classes of count(object, object, object, object)).

start object

The range starts in slice notation, broadcast; null is NumPy's default 0.

end object

The range ends in slice notation, broadcast; null is NumPy's None.

Returns

NDArray

A plain int64 array of the broadcast shape (0-d for scalar operands).

Exceptions

ArgumentNullException

a or sub is null.

TypeError

No loop for the operand classes; two different StringDType NA objects.

TypeError

A start / end that cannot reach int64 by a same_kind cast.

OverflowException

A start / end literal past int64.

IncorrectShapeException

The operands do not broadcast.

ValueError

A StringDType NA whose NA object is not a string; a chararray operand beside a StringDType one that NumPy's trivial loop copies into StringDType() (0-d, or 1-d with at most np.getbufsize() elements: Can only create a chararray from string data.; a larger one computes NumPy's plain result).

greater(object, object)

NumPy's np.char.greater(x1, x2): x1 > x2 element-wise after stripping trailing NULs and ASCII whitespace — compare_chararrays(x1, x2, '>', True).

public NDArray greater(object x1, object x2)

Parameters

x1 object

The first operand (see equal(object, object)).

x2 object

The second operand.

Returns

NDArray

The bool result, or null (NumPy's NotImplemented) for an S / U pair.

Exceptions

ArgumentNullException

An operand is null.

TypeError

An operand is not S / U text.

IncorrectShapeException

The operands do not broadcast.

greater_equal(object, object)

NumPy's np.char.greater_equal(x1, x2): x1 >= x2 element-wise after stripping trailing NULs and ASCII whitespace — compare_chararrays(x1, x2, '>=', True). The stripped strings compare unit by unit as unsigned values (bytes for S, UCS-4 units for U).

public NDArray greater_equal(object x1, object x2)

Parameters

x1 object

The first operand (see equal(object, object)).

x2 object

The second operand.

Returns

NDArray

The bool result, or null (NumPy's NotImplemented) for an S / U pair.

Exceptions

ArgumentNullException

An operand is null.

TypeError

An operand is not S / U text.

IncorrectShapeException

The operands do not broadcast.

index(object, object, object, object)

NumPy's np.char.index(a, sub, start=0, end=None), which IS index(NDArray, NDArray, NDArray, NDArray): find(object, object, object, object), but an element with no match raises ValueError: substring not found.

public NDArray index(object a, object sub, object start = null, object end = null)

Parameters

a object

The searched strings: an S / U / StringDType array or a text array_like.

sub object

The substrings, broadcast (the classes of count(object, object, object, object)).

start object

The range starts in slice notation, broadcast; null is NumPy's default 0.

end object

The range ends in slice notation, broadcast; null is NumPy's None.

Returns

NDArray

A plain int64 array of the broadcast shape (0-d for scalar operands).

Exceptions

ArgumentNullException

a or sub is null.

TypeError

No loop for the operand classes; two different StringDType NA objects.

TypeError

A start / end that cannot reach int64 by a same_kind cast.

OverflowException

A start / end literal past int64.

IncorrectShapeException

The operands do not broadcast.

ValueError

An element without a match (substring not found); a StringDType NA whose NA object is not a string; a chararray operand beside a StringDType one that NumPy's trivial loop copies into StringDType() (0-d, or 1-d with at most np.getbufsize() elements: Can only create a chararray from string data.; a larger one computes NumPy's plain result).

isalnum(object, NDArray, NDArray, DType)

NumPy's np.char.isalnum(x), which IS the isalnum(NDArray, NDArray, NDArray, DType) ufunc: True for each element whose text has at least one character and only alphanumeric characters (CPython's str.isalnum: alphabetic, decimal, digit or numeric). The text is the element's characters without its trailing NULs, so a chararray's trailing whitespace counts: 'a1' is True; a stored 'ab ' is False (its trailing spaces are not alphanumeric).

public NDArray isalnum(object x, NDArray @out = null, NDArray where = null, DType dtype = null)

Parameters

x object

The strings: an S / U / StringDType array or a text array_like (see the class remarks: a byte[] is Python bytes). A number has no loop.

out NDArray

An output to write into and return (any dtype bool casts to under same_kind: a number receives 0 / 1, a text output 'True' / 'False' cut to its width), or null.

where NDArray

A bool mask: only elements where it is True are computed, the others keep out's values (uninitialized in a fresh result), or null for NumPy's where=True.

dtype DType

NumPy's dtype=: only bool has a loop; null leaves the loop to the operand.

Returns

NDArray

A plain bool array of x's shape (0-d for a scalar), or out. A chararray x still gives a plain array; a chararray out comes back as a new view of it.

Exceptions

ArgumentNullException

x is null (see the class remarks).

TypeError

x is not text, or dtype is not bool (NumPy's no-loop text, which names a C# number by its default DType: Int64DType, Float64DType).

TypeError

out cannot receive bool (the same_kind output cast).

ArgumentException

A non-bool where; operands that do not broadcast with out / where.

ValueError

A read-only out; a selected StringDType NA whose descriptor's NA object is neither NaN-like nor a string.

NotSupportedException

x has no NumSharp array form (an object NumPy would hold in an object array, which has no loop either).

isalpha(object, NDArray, NDArray, DType)

NumPy's np.char.isalpha(x), which IS the isalpha(NDArray, NDArray, NDArray, DType) ufunc: True for each element whose text has at least one character and only alphabetic characters (CPython's str.isalpha: the Unicode letter categories). The text is the element's characters without its trailing NULs, so a chararray's trailing whitespace counts: 'abc' is True; a stored 'ab ' is False, though its element c[i] reads 'ab'.

public NDArray isalpha(object x, NDArray @out = null, NDArray where = null, DType dtype = null)

Parameters

x object

The strings: an S / U / StringDType array or a text array_like (see the class remarks: a byte[] is Python bytes). A number has no loop.

out NDArray

An output to write into and return (any dtype bool casts to under same_kind: a number receives 0 / 1, a text output 'True' / 'False' cut to its width), or null.

where NDArray

A bool mask: only elements where it is True are computed, the others keep out's values (uninitialized in a fresh result), or null for NumPy's where=True.

dtype DType

NumPy's dtype=: only bool has a loop; null leaves the loop to the operand.

Returns

NDArray

A plain bool array of x's shape (0-d for a scalar), or out. A chararray x still gives a plain array; a chararray out comes back as a new view of it.

Exceptions

ArgumentNullException

x is null (see the class remarks).

TypeError

x is not text, or dtype is not bool (NumPy's no-loop text, which names a C# number by its default DType: Int64DType, Float64DType).

TypeError

out cannot receive bool (the same_kind output cast).

ArgumentException

A non-bool where; operands that do not broadcast with out / where.

ValueError

A read-only out; a selected StringDType NA whose descriptor's NA object is neither NaN-like nor a string.

NotSupportedException

x has no NumSharp array form (an object NumPy would hold in an object array, which has no loop either).

isdecimal(object, NDArray, NDArray, DType)

NumPy's np.char.isdecimal(x), which IS the isdecimal(NDArray, NDArray, NDArray, DType) ufunc: True for each element whose text has at least one character and only decimal characters (CPython's str.isdecimal: '٣' is one, '²' is not); U and StringDType only: an S operand has no loop. The text is the element's characters without its trailing NULs, so a chararray's trailing whitespace counts: '123' is True; a stored '12 ' is False.

public NDArray isdecimal(object x, NDArray @out = null, NDArray where = null, DType dtype = null)

Parameters

x object

The strings: an S / U / StringDType array or a text array_like (see the class remarks: a byte[] is Python bytes). A number has no loop.

out NDArray

An output to write into and return (any dtype bool casts to under same_kind: a number receives 0 / 1, a text output 'True' / 'False' cut to its width), or null.

where NDArray

A bool mask: only elements where it is True are computed, the others keep out's values (uninitialized in a fresh result), or null for NumPy's where=True.

dtype DType

NumPy's dtype=: only bool has a loop; null leaves the loop to the operand.

Returns

NDArray

A plain bool array of x's shape (0-d for a scalar), or out. A chararray x still gives a plain array; a chararray out comes back as a new view of it.

Exceptions

ArgumentNullException

x is null (see the class remarks).

TypeError

x is not text (an S operand too: NumPy's ufunc has no bytes loop), or dtype is not bool (NumPy's no-loop text, which names a C# number by its default DType: Int64DType, Float64DType).

TypeError

out cannot receive bool (the same_kind output cast).

ArgumentException

A non-bool where; operands that do not broadcast with out / where.

ValueError

A read-only out; a selected StringDType NA whose descriptor's NA object is neither NaN-like nor a string.

NotSupportedException

x has no NumSharp array form (an object NumPy would hold in an object array, which has no loop either).

isdigit(object, NDArray, NDArray, DType)

NumPy's np.char.isdigit(x), which IS the isdigit(NDArray, NDArray, NDArray, DType) ufunc: True for each element whose text has at least one character and only digits (CPython's str.isdigit: the decimal digits and the other digits, such as '²'; not '½'). The text is the element's characters without its trailing NULs, so a chararray's trailing whitespace counts: '123' is True; '½' is False.

public NDArray isdigit(object x, NDArray @out = null, NDArray where = null, DType dtype = null)

Parameters

x object

The strings: an S / U / StringDType array or a text array_like (see the class remarks: a byte[] is Python bytes). A number has no loop.

out NDArray

An output to write into and return (any dtype bool casts to under same_kind: a number receives 0 / 1, a text output 'True' / 'False' cut to its width), or null.

where NDArray

A bool mask: only elements where it is True are computed, the others keep out's values (uninitialized in a fresh result), or null for NumPy's where=True.

dtype DType

NumPy's dtype=: only bool has a loop; null leaves the loop to the operand.

Returns

NDArray

A plain bool array of x's shape (0-d for a scalar), or out. A chararray x still gives a plain array; a chararray out comes back as a new view of it.

Exceptions

ArgumentNullException

x is null (see the class remarks).

TypeError

x is not text, or dtype is not bool (NumPy's no-loop text, which names a C# number by its default DType: Int64DType, Float64DType).

TypeError

out cannot receive bool (the same_kind output cast).

ArgumentException

A non-bool where; operands that do not broadcast with out / where.

ValueError

A read-only out; a selected StringDType NA whose descriptor's NA object is neither NaN-like nor a string.

NotSupportedException

x has no NumSharp array form (an object NumPy would hold in an object array, which has no loop either).

islower(object, NDArray, NDArray, DType)

NumPy's np.char.islower(x), which IS the islower(NDArray, NDArray, NDArray, DType) ufunc: True for each element whose text has at least one cased character and every cased character lowercase. The text is the element's characters without its trailing NULs, so a chararray's trailing whitespace counts: a stored 'ab ' is True (spaces are uncased); 'aBc' is False.

public NDArray islower(object x, NDArray @out = null, NDArray where = null, DType dtype = null)

Parameters

x object

The strings: an S / U / StringDType array or a text array_like (see the class remarks: a byte[] is Python bytes). A number has no loop.

out NDArray

An output to write into and return (any dtype bool casts to under same_kind: a number receives 0 / 1, a text output 'True' / 'False' cut to its width), or null.

where NDArray

A bool mask: only elements where it is True are computed, the others keep out's values (uninitialized in a fresh result), or null for NumPy's where=True.

dtype DType

NumPy's dtype=: only bool has a loop; null leaves the loop to the operand.

Returns

NDArray

A plain bool array of x's shape (0-d for a scalar), or out. A chararray x still gives a plain array; a chararray out comes back as a new view of it.

Exceptions

ArgumentNullException

x is null (see the class remarks).

TypeError

x is not text, or dtype is not bool (NumPy's no-loop text, which names a C# number by its default DType: Int64DType, Float64DType).

TypeError

out cannot receive bool (the same_kind output cast).

ArgumentException

A non-bool where; operands that do not broadcast with out / where.

ValueError

A read-only out; a selected StringDType NA whose descriptor's NA object is neither NaN-like nor a string.

NotSupportedException

x has no NumSharp array form (an object NumPy would hold in an object array, which has no loop either).

isnumeric(object, NDArray, NDArray, DType)

NumPy's np.char.isnumeric(x), which IS the isnumeric(NDArray, NDArray, NDArray, DType) ufunc: True for each element whose text has at least one character and only numeric characters (CPython's str.isnumeric: digits, fractions such as '½', Roman and CJK numerals); U and StringDType only: an S operand has no loop. The text is the element's characters without its trailing NULs, so a chararray's trailing whitespace counts: '½' is True; 'a1' is False.

public NDArray isnumeric(object x, NDArray @out = null, NDArray where = null, DType dtype = null)

Parameters

x object

The strings: an S / U / StringDType array or a text array_like (see the class remarks: a byte[] is Python bytes). A number has no loop.

out NDArray

An output to write into and return (any dtype bool casts to under same_kind: a number receives 0 / 1, a text output 'True' / 'False' cut to its width), or null.

where NDArray

A bool mask: only elements where it is True are computed, the others keep out's values (uninitialized in a fresh result), or null for NumPy's where=True.

dtype DType

NumPy's dtype=: only bool has a loop; null leaves the loop to the operand.

Returns

NDArray

A plain bool array of x's shape (0-d for a scalar), or out. A chararray x still gives a plain array; a chararray out comes back as a new view of it.

Exceptions

ArgumentNullException

x is null (see the class remarks).

TypeError

x is not text (an S operand too: NumPy's ufunc has no bytes loop), or dtype is not bool (NumPy's no-loop text, which names a C# number by its default DType: Int64DType, Float64DType).

TypeError

out cannot receive bool (the same_kind output cast).

ArgumentException

A non-bool where; operands that do not broadcast with out / where.

ValueError

A read-only out; a selected StringDType NA whose descriptor's NA object is neither NaN-like nor a string.

NotSupportedException

x has no NumSharp array form (an object NumPy would hold in an object array, which has no loop either).

isspace(object, NDArray, NDArray, DType)

NumPy's np.char.isspace(x), which IS the isspace(NDArray, NDArray, NDArray, DType) ufunc: True for each element whose text has at least one character and only whitespace (CPython's str.isspace for U / StringDType; space and \t–\r for S). The text is the element's characters without its trailing NULs, so a chararray's trailing whitespace counts: ' ' is True; an empty element is False.

public NDArray isspace(object x, NDArray @out = null, NDArray where = null, DType dtype = null)

Parameters

x object

The strings: an S / U / StringDType array or a text array_like (see the class remarks: a byte[] is Python bytes). A number has no loop.

out NDArray

An output to write into and return (any dtype bool casts to under same_kind: a number receives 0 / 1, a text output 'True' / 'False' cut to its width), or null.

where NDArray

A bool mask: only elements where it is True are computed, the others keep out's values (uninitialized in a fresh result), or null for NumPy's where=True.

dtype DType

NumPy's dtype=: only bool has a loop; null leaves the loop to the operand.

Returns

NDArray

A plain bool array of x's shape (0-d for a scalar), or out. A chararray x still gives a plain array; a chararray out comes back as a new view of it.

Exceptions

ArgumentNullException

x is null (see the class remarks).

TypeError

x is not text, or dtype is not bool (NumPy's no-loop text, which names a C# number by its default DType: Int64DType, Float64DType).

TypeError

out cannot receive bool (the same_kind output cast).

ArgumentException

A non-bool where; operands that do not broadcast with out / where.

ValueError

A read-only out; a selected StringDType NA whose descriptor's NA object is neither NaN-like nor a string.

NotSupportedException

x has no NumSharp array form (an object NumPy would hold in an object array, which has no loop either).

istitle(object, NDArray, NDArray, DType)

NumPy's np.char.istitle(x), which IS the istitle(NDArray, NDArray, NDArray, DType) ufunc: True for each element whose text is titlecased: an uppercase or titlecase character never follows a cased character, a lowercase one always does, and at least one character is cased. The text is the element's characters without its trailing NULs, so a chararray's trailing whitespace counts: 'Abc Def' is True; 'ABC' is False.

public NDArray istitle(object x, NDArray @out = null, NDArray where = null, DType dtype = null)

Parameters

x object

The strings: an S / U / StringDType array or a text array_like (see the class remarks: a byte[] is Python bytes). A number has no loop.

out NDArray

An output to write into and return (any dtype bool casts to under same_kind: a number receives 0 / 1, a text output 'True' / 'False' cut to its width), or null.

where NDArray

A bool mask: only elements where it is True are computed, the others keep out's values (uninitialized in a fresh result), or null for NumPy's where=True.

dtype DType

NumPy's dtype=: only bool has a loop; null leaves the loop to the operand.

Returns

NDArray

A plain bool array of x's shape (0-d for a scalar), or out. A chararray x still gives a plain array; a chararray out comes back as a new view of it.

Exceptions

ArgumentNullException

x is null (see the class remarks).

TypeError

x is not text, or dtype is not bool (NumPy's no-loop text, which names a C# number by its default DType: Int64DType, Float64DType).

TypeError

out cannot receive bool (the same_kind output cast).

ArgumentException

A non-bool where; operands that do not broadcast with out / where.

ValueError

A read-only out; a selected StringDType NA whose descriptor's NA object is neither NaN-like nor a string.

NotSupportedException

x has no NumSharp array form (an object NumPy would hold in an object array, which has no loop either).

isupper(object, NDArray, NDArray, DType)

NumPy's np.char.isupper(x), which IS the isupper(NDArray, NDArray, NDArray, DType) ufunc: True for each element whose text has at least one cased character and every cased character uppercase. The text is the element's characters without its trailing NULs, so a chararray's trailing whitespace counts: a stored 'AB ' is True (spaces are uncased); 'Ab' is False.

public NDArray isupper(object x, NDArray @out = null, NDArray where = null, DType dtype = null)

Parameters

x object

The strings: an S / U / StringDType array or a text array_like (see the class remarks: a byte[] is Python bytes). A number has no loop.

out NDArray

An output to write into and return (any dtype bool casts to under same_kind: a number receives 0 / 1, a text output 'True' / 'False' cut to its width), or null.

where NDArray

A bool mask: only elements where it is True are computed, the others keep out's values (uninitialized in a fresh result), or null for NumPy's where=True.

dtype DType

NumPy's dtype=: only bool has a loop; null leaves the loop to the operand.

Returns

NDArray

A plain bool array of x's shape (0-d for a scalar), or out. A chararray x still gives a plain array; a chararray out comes back as a new view of it.

Exceptions

ArgumentNullException

x is null (see the class remarks).

TypeError

x is not text, or dtype is not bool (NumPy's no-loop text, which names a C# number by its default DType: Int64DType, Float64DType).

TypeError

out cannot receive bool (the same_kind output cast).

ArgumentException

A non-bool where; operands that do not broadcast with out / where.

ValueError

A read-only out; a selected StringDType NA whose descriptor's NA object is neither NaN-like nor a string.

NotSupportedException

x has no NumSharp array form (an object NumPy would hold in an object array, which has no loop either).

join(object, object)

NumPy's np.char.join(sep, seq): every element of seq — a STRING — with its characters joined by the separator element (join('-', 'osd') is 'o-s-d'), as Python's sep.join(seq) iterates a string.

public NDArray join(object sep, object seq)

Parameters

sep object

The separators: S / U / StringDType text or a text array_like.

seq object

The strings, broadcast against sep.

Returns

NDArray

The joined text as NumPy's _to_bytes_or_str_array builds it: of seq's class (U / S as wide as the longest result, at least 1; StringDType() with default parameters), a fresh C-ordered array; for an empty broadcast an empty array of seq's dtype, whatever it is.

Remarks

One overload, NumPy's signature. An S sequence joins only when empty (b'-'.join(b'ab') iterates ints), as in NumPy. A list of words is not a sequence here: np.asarray(['ab', 'cd']) is a string array, so each word's characters are joined.

An object seq of lists (split(object, object, object)'s result) is joined element by element as NumPy's _vec_string joins it — each element's list items, its TypeError for a list item of the wrong class — and then raises NumPy 2.4.2's own error, because _to_bytes_or_str_array calls ObjectDType(n), which takes no argument: the idiom np.char.join(' ', np.char.split(a)) raises in NumPy 2.4.2, and here.

Exceptions

TypeError

sep is not text (string operation on non-string array, also for null: Python's None); per element, in NumPy's order: a StringDType NA separator that is not a str (descriptor 'join' for 'str' objects doesn't apply to a 'NoneType' object), a non-iterable sequence (a number or None — a null seq is Python's None —: can only join an iterable), a sequence of the other class (sequence item 0: expected str instance, int found — iterating bytes gives ints —, sequence item 0: expected a bytes-like object, str found), and an object seq (a C# list holding null) once every element joined (NumSharp.Backends.Strings.NDCharObjectPath.ObjectDTypeText, NumPy 2.4.2's own failure).

ValueError

A ragged list argument.

SystemError

A U separator or sequence that is one code unit above U+10FFFF, or a U sequence holding such a unit (iterating it creates the character).

IncorrectShapeException

The arguments do not broadcast.

NotSupportedException

NumPy's result is an empty OBJECT array, which an NDArray result cannot hold: an empty broadcast of an object seq — an NDListArray (split(object, object, object)'s lists) or a C# list holding null.

less(object, object)

NumPy's np.char.less(x1, x2): x1 < x2 element-wise after stripping trailing NULs and ASCII whitespace — compare_chararrays(x1, x2, '<', True).

public NDArray less(object x1, object x2)

Parameters

x1 object

The first operand (see equal(object, object)).

x2 object

The second operand.

Returns

NDArray

The bool result, or null (NumPy's NotImplemented) for an S / U pair.

Exceptions

ArgumentNullException

An operand is null.

TypeError

An operand is not S / U text.

IncorrectShapeException

The operands do not broadcast.

less_equal(object, object)

NumPy's np.char.less_equal(x1, x2): x1 <= x2 element-wise after stripping trailing NULs and ASCII whitespace — compare_chararrays(x1, x2, '<=', True).

public NDArray less_equal(object x1, object x2)

Parameters

x1 object

The first operand (see equal(object, object)).

x2 object

The second operand.

Returns

NDArray

The bool result, or null (NumPy's NotImplemented) for an S / U pair.

Exceptions

ArgumentNullException

An operand is null.

TypeError

An operand is not S / U text.

IncorrectShapeException

The operands do not broadcast.

ljust(object, object, object)

NumPy's np.char.ljust(a, width, fillchar=' '), which IS ljust(NDArray, NDArray, NDArray): each element left-justified in a string of width characters, padded on the right with fillchar.

public NDArray ljust(object a, object width, object fillchar = null)

Parameters

a object

The strings: an S / U / StringDType array or a text array_like.

width object

The integer widths, broadcast.

fillchar object

The one-character fills, broadcast; null is NumPy's default ' '.

Returns

NDArray

A fresh array (see center(object, object, object)).

Exceptions

ArgumentNullException

a or width is null.

TypeError

See center(object, object, object).

ValueError

An empty broadcast; a StringDType NA its rule refuses; a chararray operand beside a StringDType one that NumPy's trivial loop copies into StringDType() (0-d, or 1-d with at most np.getbufsize() elements: Can only create a chararray from string data.; a larger one computes NumPy's plain result).

UnicodeEncodeError

A non-ASCII fill for an S operand.

IncorrectShapeException

The operands do not broadcast.

OverflowException

A StringDType result past sys.maxsize bytes.

lower(object)

NumPy's np.char.lower(a), which IS lower(NDArray): each element's text lowercased — CPython's str.lower (the full mappings and the final sigma) for U and StringDType, bytes.lower (ASCII letters only) for S.

public NDArray lower(object a)

Parameters

a object

The strings: an S / U / StringDType array or a text array_like (see the class remarks).

Returns

NDArray

A fresh C-ordered PLAIN array of a's dtype (a chararray operand too), 0-d for a scalar; an S / U result keeps the element width.

Exceptions

ArgumentNullException

a is null (see the class remarks).

TypeError

a is not text (string operation on non-string array); a StringDType NA whose NA object is not a str.

SystemError

A U element holding a code unit past U+10FFFF.

NotSupportedException

a has no NumSharp array form.

lstrip(object, object)

NumPy's np.char.lstrip(a, chars=None), which IS lstrip(NDArray, NDArray): each element without its LEADING characters found in chars (whitespace for null).

public NDArray lstrip(object a, object chars = null)

Parameters

a object

The strings: an S / U / StringDType array or a text array_like.

chars object

The characters to remove, as a set, broadcast (see strip(object, object)); null strips whitespace.

Returns

NDArray

A fresh array of a's dtype (a chararray view of it for a chararray a).

Exceptions

ArgumentNullException

a is null.

TypeError

No loop for the operand classes; two different StringDType NA objects.

IncorrectShapeException

The operands do not broadcast.

ValueError

A StringDType NA its rule refuses; a chararray operand beside a StringDType one that NumPy's trivial loop copies into StringDType() (0-d, or 1-d with at most np.getbufsize() elements: Can only create a chararray from string data.; a larger one computes NumPy's plain result).

mod(object, object)

NumPy's np.char.mod(a, values): a % values element-wise — CPython's % formatting of each element of a with the broadcast element of values. It IS mod(NDArray, object) (NumPy re-exports the same function object).

public NDArray mod(object a, object values)

Parameters

a object

The format strings: an S / U / StringDType array or a text array_like (see the class remarks: a C# string is a str, a byte[] Python bytes).

values object

The values, converted as NumPy's np.asarray converts them and broadcast against a, ONE value per element (see mod(NDArray, object): a C# number is a Python number, a tuple or a list a sequence, a dict a mapping for %(key)s specs, null Python's None).

Returns

NDArray

A fresh C-ordered PLAIN array over the broadcast shape — U / S (by a's class) as wide as the longest result, at least 1; a default StringDType array for a StringDType operand; an empty array of a's dtype when the broadcast is empty. A chararray operand gives a plain array too (np.asarray drops the class); chararray % values is the chararray form.

Remarks

np.@char.mod(new[] { "%d", "%x" }, 255) is ["255", "ff"] (U3); an error ends the call at the first element (C order) that raises, as in NumPy. Over S, %s writes a NumPy scalar's raw bytes (the buffer protocol): np.@char.mod(new[] { new byte[] { (byte)'%', (byte)'s' } }, "X") holds the np.str_'s UCS-4 bytes b"X\x00\x00\x00", read back as b"X" in an S4 result.

Exceptions

ArgumentNullException

a is null (see the class remarks).

TypeError

a is not text (string operation on non-string array); the value count does not fit the format (not enough arguments for format string, not all arguments converted during string formatting); a conversion the value's type refuses (%d format: a real number is required, not numpy.str_); %(key)s without a mapping; a StringDType result holding a surrogate.

ValueError

A malformed format (incomplete format, unsupported format character 'y' (0x79) at index 1); a NaN under an integer conversion; a ragged values list.

OverflowException

An infinity under an integer conversion; a %c argument out of range; an int too large for a float.

IndexError

A %(key)s lookup on a NumPy scalar.

KeyError

A %(key)s missing from a dict.

SystemError

A U element of one unit past U+10FFFF.

IncorrectShapeException

The operands do not broadcast.

NotSupportedException

A value with no NumSharp form (an object array of lists).

multiply(object, object)

NumPy's np.char.multiply(a, i): every string repeated i times (a count below 1 gives an empty string) — np.strings.multiply(a, i) with its TypeError re-raised as ValueError("Can only multiply by integers"), the module's backward-compatible rule.

public NDArray multiply(object a, object i)

Parameters

a object

The strings (an S / U array or a text array_like).

i object

The repeat counts: an integer array_like, broadcast against a.

Returns

NDArray

A fresh text array of a's class, as wide as the longest repetition.

Remarks

A NEP 55 StringDType a with an integer count computes NumPy's a * i (multiply(NDArray, NDArray)'s StringDType branch); a TypeError there is re-raised as the ValueError above, as for every class.

Exceptions

ArgumentNullException

An operand is null.

ValueError

Every TypeError of multiply(NDArray, NDArray): a count that is not an integer (a float, a bool, text), a non-text a, an output width that is no valid descriptor (a uint64 count, a repetition wider than any descriptor) — all Can only multiply by integers (probed against NumPy 2.4.2). Also NumPy's own ValueErrors: an empty broadcast result (zero-size array to reduction operation maximum which has no identity) and operands that do not broadcast.

OverflowException

A string's len * i exceeds sys.maxsize ("Overflow encountered in string multiply"): an OverflowError, not a TypeError, so it passes through.

IncorrectShapeException

a and i do not broadcast.

not_equal(object, object)

NumPy's np.char.not_equal(x1, x2): x1 != x2 element-wise after stripping trailing NULs and ASCII whitespace — compare_chararrays(x1, x2, '!=', True).

public NDArray not_equal(object x1, object x2)

Parameters

x1 object

The first operand (see equal(object, object)).

x2 object

The second operand.

Returns

NDArray

The bool result, or null (NumPy's NotImplemented) for an S / U pair.

Exceptions

ArgumentNullException

An operand is null.

TypeError

An operand is not S / U text.

IncorrectShapeException

The operands do not broadcast.

partition(object, object)

NumPy's np.char.partition(a, sep): each element split around the FIRST occurrence of sep into the part before it, the separator and the part after it (without a match: the element and two empty strings), stacked as ONE array whose last axis holds the three parts — np.stack(np.strings.partition(a, sep), axis=-1). partition(NDArray, NDArray) returns the three parts as three arrays instead.

public NDArray partition(object a, object sep)

Parameters

a object

The strings: an S / U / StringDType array or a text array_like (see the class remarks). A number array is cast to text the way NumPy casts it (np.char.partition(5, ' ') raises NumPy's invalid literal for int()).

sep object

The separators, broadcast against a: cast to a's dtype for S / U (a number is its text, 1 is '1'); a StringDType a needs a StringDType separator (NumPy 2.4.2 has no (StringDType, str) loop).

Returns

NDArray

A plain array of the broadcast shape plus a last axis of length 3, as wide as its widest part (S / U) or StringDType; laid out as NumPy's np.stack lays out the parts (C order for a C-ordered input). A chararray input still gives a plain array: np.stack keeps no subclass.

Remarks

For S / U NumPy computes the three parts as field views of one structured array and stacks them; NumSharp computes three arrays and stacks them the same way. The stacked result is a fresh copy in both, with NumPy's dtype, values and strides (an F-ordered input gives NumPy's permuted layout, neither C nor F).

Exceptions

ArgumentNullException

An operand is null (see the class remarks).

ValueError

An empty separator (empty separator); an empty broadcast (zero-size array to reduction operation maximum which has no identity, NumPy's sizing); a number operand that cannot be cast to the other's text (invalid literal for int() with base 10: np.str_(' ')); a StringDType NA whose NA object is not a string.

TypeError

No common dtype or no loop for the classes (NumPy's texts: a StringDType array with a U separator, a bytes separator beside StringDType); two different StringDType NA objects.

UnicodeEncodeError

A non-ASCII separator cast to S.

IncorrectShapeException

The operands do not broadcast.

replace(object, object, object, object)

NumPy's np.char.replace(a, old, new, count=-1), which IS replace(NDArray, NDArray, NDArray, NDArray): each element with its occurrences of old replaced by new, left to right, at most count of them (a negative count replaces all; an empty old inserts new between every character and at both ends).

public NDArray replace(object a, object old, object @new, object count = null)

Parameters

a object

The strings: an S / U / StringDType array or a text array_like.

old object

The searched strings, broadcast. A C# string (NumPy's Python str, which has no dtype) or byte[] is cast to a's dtype first, truncated to its width; an array keeps its own dtype.

new object

The replacements, broadcast (the rule of old).

count object

The most replacements per element: an integer array or literal, broadcast; null is NumPy's default -1 (NumPy's explicit None raises unsupported type object for operand 'count', which no C# argument can express).

Returns

NDArray

A fresh array: for S / U a's class at the widest result width, laid out like a; StringDType for StringDType. A chararray a gives a chararray view of it.

Exceptions

ArgumentNullException

a, old or new is null.

TypeError

count is not an integer array (unsupported type float64 for operand 'count'); no common dtype or no loop for the classes; a uint64 count (NumPy's float descriptor); two different StringDType NA objects.

IncorrectShapeException

A statement's operands do not broadcast.

ValueError

An empty broadcast; a number cast to text; a StringDType NA its rule refuses; a chararray operand beside a StringDType one that NumPy's trivial loop copies into StringDType() (0-d, or 1-d with at most np.getbufsize() elements: Can only create a chararray from string data.; a larger one computes NumPy's plain result).

UnicodeEncodeError

A non-ASCII old / new cast to S.

rfind(object, object, object, object)

NumPy's np.char.rfind(a, sub, start=0, end=None), which IS rfind(NDArray, NDArray, NDArray, NDArray): for each element, the highest index where sub occurs inside a[start:end], or -1 (an empty substring is found at the end of the range).

public NDArray rfind(object a, object sub, object start = null, object end = null)

Parameters

a object

The searched strings: an S / U / StringDType array or a text array_like.

sub object

The substrings, broadcast (the classes of count(object, object, object, object)).

start object

The range starts in slice notation, broadcast; null is NumPy's default 0.

end object

The range ends in slice notation, broadcast; null is NumPy's None.

Returns

NDArray

A plain int64 array of the broadcast shape (0-d for scalar operands).

Exceptions

ArgumentNullException

a or sub is null.

TypeError

No loop for the operand classes; two different StringDType NA objects.

TypeError

A start / end that cannot reach int64 by a same_kind cast.

OverflowException

A start / end literal past int64.

IncorrectShapeException

The operands do not broadcast.

ValueError

A StringDType NA whose NA object is not a string; a chararray operand beside a StringDType one that NumPy's trivial loop copies into StringDType() (0-d, or 1-d with at most np.getbufsize() elements: Can only create a chararray from string data.; a larger one computes NumPy's plain result).

rindex(object, object, object, object)

NumPy's np.char.rindex(a, sub, start=0, end=None), which IS rindex(NDArray, NDArray, NDArray, NDArray): rfind(object, object, object, object), but an element with no match raises ValueError: substring not found.

public NDArray rindex(object a, object sub, object start = null, object end = null)

Parameters

a object

The searched strings: an S / U / StringDType array or a text array_like.

sub object

The substrings, broadcast (the classes of count(object, object, object, object)).

start object

The range starts in slice notation, broadcast; null is NumPy's default 0.

end object

The range ends in slice notation, broadcast; null is NumPy's None.

Returns

NDArray

A plain int64 array of the broadcast shape (0-d for scalar operands).

Exceptions

ArgumentNullException

a or sub is null.

TypeError

No loop for the operand classes; two different StringDType NA objects.

TypeError

A start / end that cannot reach int64 by a same_kind cast.

OverflowException

A start / end literal past int64.

IncorrectShapeException

The operands do not broadcast.

ValueError

An element without a match; a StringDType NA whose NA object is not a string; a chararray operand beside a StringDType one that NumPy's trivial loop copies into StringDType() (0-d, or 1-d with at most np.getbufsize() elements: Can only create a chararray from string data.; a larger one computes NumPy's plain result).

rjust(object, object, object)

NumPy's np.char.rjust(a, width, fillchar=' '), which IS rjust(NDArray, NDArray, NDArray): each element right-justified in a string of width characters, padded on the left with fillchar.

public NDArray rjust(object a, object width, object fillchar = null)

Parameters

a object

The strings: an S / U / StringDType array or a text array_like.

width object

The integer widths, broadcast.

fillchar object

The one-character fills, broadcast; null is NumPy's default ' '.

Returns

NDArray

A fresh array (see center(object, object, object)).

Exceptions

ArgumentNullException

a or width is null.

TypeError

See center(object, object, object).

ValueError

An empty broadcast; a StringDType NA its rule refuses; a chararray operand beside a StringDType one that NumPy's trivial loop copies into StringDType() (0-d, or 1-d with at most np.getbufsize() elements: Can only create a chararray from string data.; a larger one computes NumPy's plain result).

UnicodeEncodeError

A non-ASCII fill for an S operand.

IncorrectShapeException

The operands do not broadcast.

OverflowException

A StringDType result past sys.maxsize bytes.

rpartition(object, object)

NumPy's np.char.rpartition(a, sep): each element split around the LAST occurrence of sep into the part before it, the separator and the part after it (without a match: two empty strings and the element), stacked as one array whose last axis holds the three parts — np.stack(np.strings.rpartition(a, sep), axis=-1).

public NDArray rpartition(object a, object sep)

Parameters

a object

The strings (see partition(object, object)).

sep object

The separators, broadcast and cast as partition(object, object) casts them.

Returns

NDArray

A plain array of the broadcast shape plus a last axis of length 3 (see partition(object, object)).

Exceptions

ArgumentNullException

An operand is null.

ValueError

An empty separator; an empty broadcast; a number operand that cannot be cast to the other's text; a StringDType NA whose NA object is not a string.

TypeError

No common dtype or no loop for the classes; two different StringDType NA objects.

UnicodeEncodeError

A non-ASCII separator cast to S.

IncorrectShapeException

The operands do not broadcast.

rsplit(object, object, object)

NumPy's np.char.rsplit(a, sep=None, maxsplit=None): split(object, object, object) from the right — with a maxsplit, the splits counted from the end ('a,b,c'.rsplit(',', 1) is ['a,b', 'c']). Without one, the same words as split(object, object, object).

public NDListArray rsplit(object a, object sep = null, object maxsplit = null)

Parameters

a object

The text (see split(object, object, object)).

sep object

The separator (see split(object, object, object)).

maxsplit object

The most splits per element, from the right (see split(object, object, object)).

Returns

NDListArray

NumPy's object array of lists (NDListArray).

Exceptions

TypeError

As split(object, object, object) (the descriptor names 'rsplit').

OverflowException

A maxsplit past Py_ssize_t.

ValueError

An empty separator, or a ragged list argument.

SystemError

A one-unit U element, separator or word above U+10FFFF.

IncorrectShapeException

The arguments do not broadcast.

rstrip(object, object)

NumPy's np.char.rstrip(a, chars=None), which IS rstrip(NDArray, NDArray): each element without its TRAILING characters found in chars (whitespace for null).

public NDArray rstrip(object a, object chars = null)

Parameters

a object

The strings: an S / U / StringDType array or a text array_like.

chars object

The characters to remove, as a set, broadcast (see strip(object, object)); null strips whitespace.

Returns

NDArray

A fresh array of a's dtype (a chararray view of it for a chararray a).

Exceptions

ArgumentNullException

a is null.

TypeError

No loop for the operand classes; two different StringDType NA objects.

IncorrectShapeException

The operands do not broadcast.

ValueError

A StringDType NA its rule refuses; a chararray operand beside a StringDType one that NumPy's trivial loop copies into StringDType() (0-d, or 1-d with at most np.getbufsize() elements: Can only create a chararray from string data.; a larger one computes NumPy's plain result).

split(object, object, object)

NumPy's np.char.split(a, sep=None, maxsplit=None): every element's list of words, as Python's str.split / bytes.split returns it. With sep null the words are the runs of non-whitespace (CPython's 29 whitespace code points for U / StringDType, 6 ASCII bytes for S) and empty words never appear; with a separator every occurrence splits, so empty words do.

public NDListArray split(object a, object sep = null, object maxsplit = null)

Parameters

a object

The text: an S / U / StringDType array or a text array_like (see the class remarks).

sep object

The separator, broadcast per element: null (NumPy's None) for whitespace; text; for an S array also any NumPy number, whose raw bytes are the separator (NumPy's bytes.split reads a NumPy scalar through the buffer protocol: np.char.split(s, 5) splits on the 8 bytes of np.int64(5), and a str separator on its UCS-4 bytes); a C# list holding null gives some elements None (NumPy's object array).

maxsplit object

The most splits per element, broadcast: null (NumPy's None) or a negative value for no limit; any integer (NumSharp's Char is NumPy's uint16).

Returns

NDListArray

NumPy's object array of lists (NDListArray), C-ordered over the broadcast shape, 0-d for a 0-d broadcast.

Remarks

The first element (C order) that raises ends the call, as NumPy's loop does; an empty array raises none of the element errors (np.char.split(empty, '') is an empty result). Each element is the NumPy scalar _vec_string makes of it: trailing NULs are gone, embedded ones stay.

A U element shorter than the separator, or whose characters are all of a narrower kind than the separator's ('abc' split on '€'), is CPython's [self]: the list holds the element's own np.str_, which NDListArray's repr prints as np.str_('abc'), as NumPy's does.

Exceptions

TypeError

a is not text (string operation on non-string array, also for null: Python's None is an object array here, see the class remarks); per element, in NumPy's order: a StringDType NA that is not a str (descriptor 'split' for 'str' objects doesn't apply to a 'NoneType' object), a maxsplit without index ('numpy.float64' object cannot be interpreted as an integer; np.bool has none), a separator of the wrong type (must be str or None, not numpy.bytes_ for U; a bytes-like object is required, not 'str' for S with a StringDType separator).

OverflowException

A maxsplit past Py_ssize_t (Python int too large to convert to C ssize_t).

ValueError

An empty separator (empty separator); a ragged list argument (NumPy's inhomogeneous-shape text).

SystemError

A U element, separator or word that is one code unit above U+10FFFF (CPython's PyUnicode_New refusal).

IncorrectShapeException

The arguments do not broadcast (NumPy's shape mismatch: objects cannot be broadcast to a single shape. Mismatch is between arg 0 with shape (2,) and arg 1 with shape (3,).).

splitlines(object, object)

NumPy's np.char.splitlines(a, keepends=None): every element's list of lines. U / StringDType lines end at \n, \r, \r\n, \v, \f, \x1c, \x1d, \x1e, \x85, U+2028 and U+2029; S lines at \n, \r and \r\n only. A trailing boundary ends the last line (no empty line after it); an empty element has no line.

public NDListArray splitlines(object a, object keepends = null)

Parameters

a object

The text (see split(object, object, object)).

keepends object

Whether a line keeps its boundary, broadcast per element and read with Python's truth rule (PyObject_IsTrue: 0.5, 'x' and NaN are true, '' and 0 false); null (NumPy's None) is false.

Returns

NDListArray

NumPy's object array of lists (NDListArray).

Exceptions

TypeError

a is not text (null too: Python's None); a StringDType NA that is not a str (descriptor 'splitlines' for 'str' objects doesn't apply to a 'NoneType' object).

ValueError

A ragged list argument.

SystemError

A one-unit U element, keepends value or line above U+10FFFF.

IncorrectShapeException

a and keepends do not broadcast.

startswith(object, object, object, object)

NumPy's np.char.startswith(a, prefix, start=0, end=None), which IS startswith(NDArray, NDArray, NDArray, NDArray): whether each element's a[start:end] begins with prefix.

public NDArray startswith(object a, object prefix, object start = null, object end = null)

Parameters

a object

The tested strings: an S / U / StringDType array or a text array_like.

prefix object

The prefixes, broadcast (the classes of count(object, object, object, object)).

start object

The range starts in slice notation, broadcast; null is NumPy's default 0.

end object

The range ends in slice notation, broadcast; null is NumPy's None.

Returns

NDArray

A plain bool array of the broadcast shape (0-d for scalar operands).

Exceptions

ArgumentNullException

a or prefix is null.

TypeError

No loop for the operand classes; two different StringDType NA objects.

TypeError

A start / end that cannot reach int64 by a same_kind cast.

OverflowException

A start / end literal past int64.

IncorrectShapeException

The operands do not broadcast.

ValueError

A StringDType NA whose NA object is neither a string nor NaN-like (a NaN-like NA is False); a chararray operand beside a StringDType one that NumPy's trivial loop copies into StringDType() (0-d, or 1-d with at most np.getbufsize() elements: Can only create a chararray from string data.; a larger one computes NumPy's plain result).

str_len(object, NDArray, NDArray, DType)

NumPy's np.char.str_len(x), which IS the str_len(NDArray, NDArray, NDArray, DType) ufunc: the length of every element as int64 — characters for U, bytes for S, code points for StringDType. Trailing NULs never count, embedded ones do; trailing whitespace counts (a chararray's stored text is measured, not its stripped elements).

public NDArray str_len(object x, NDArray @out = null, NDArray where = null, DType dtype = null)

Parameters

x object

The strings: an S / U / StringDType array or a text array_like (see the class remarks). A number array has no loop.

out NDArray

An output to write into and return (any dtype int64 casts to under same_kind), or null.

where NDArray

A bool mask: only elements where it is True are computed, the others keep out's values (uninitialized in a fresh result), or null for NumPy's where=True.

dtype DType

NumPy's dtype=: only int64 has a loop; null leaves the loop to the operand.

Returns

NDArray

A plain int64 array of x's shape (0-d for a scalar), or out. A chararray x still gives a plain array; a chararray out comes back as a new view of it.

Exceptions

ArgumentNullException

x is null (see the class remarks).

TypeError

x is not text, or dtype is not int64 (NumPy's no-loop text).

TypeError

out cannot receive int64 (the same_kind output cast).

ArgumentException

A non-bool where; operands that do not broadcast with out / where.

ValueError

A read-only out; a StringDType NA whose descriptor's NA object is not a string (The length of a null string is undefined).

IncorrectShapeException

The operands do not broadcast.

strip(object, object)

NumPy's np.char.strip(a, chars=None), which IS strip(NDArray, NDArray): each element without its leading and trailing characters found in chars (whitespace for null), keeping a's dtype.

public NDArray strip(object a, object chars = null)

Parameters

a object

The strings: an S / U / StringDType array or a text array_like (see the class remarks).

chars object

The characters to remove, as a set, broadcast: a's class (a U set with a StringDType a); null is NumPy's None, which strips whitespace — ASCII whitespace for S, Python's str.isspace for U / StringDType.

Returns

NDArray

A fresh array of a's dtype and the broadcast shape; a chararray a gives a chararray view of it (NumPy's chararray.array_wrap).

Remarks

NumPy's trailing scan also strips NUL characters, its leading scan does not (strip(' \0ab') is '\0ab').

Exceptions

ArgumentNullException

a is null.

TypeError

No loop for the operand classes (a bytes set beside U, a number: NumPy's no-loop text, naming _strip_chars or _strip_whitespace); two different StringDType NA objects.

IncorrectShapeException

The operands do not broadcast.

ValueError

A StringDType NA its rule refuses; a chararray operand beside a StringDType one that NumPy's trivial loop copies into StringDType() (0-d, or 1-d with at most np.getbufsize() elements: Can only create a chararray from string data.; a larger one computes NumPy's plain result).

swapcase(object)

NumPy's np.char.swapcase(a), which IS swapcase(NDArray): each element's uppercase characters lowered and lowercase characters uppercased (CPython's str.swapcase / bytes.swapcase); a titlecase character such as 'Dž' is neither and stays.

public NDArray swapcase(object a)

Parameters

a object

The strings: an S / U / StringDType array or a text array_like (see the class remarks).

Returns

NDArray

A fresh C-ordered PLAIN array of a's dtype (a chararray operand too), 0-d for a scalar; an S / U result keeps the element width ('ß' swaps to 'SS', cut to fit).

Exceptions

ArgumentNullException

a is null (see the class remarks).

TypeError

a is not text (string operation on non-string array); a StringDType NA whose NA object is not a str.

SystemError

A U element holding a code unit past U+10FFFF.

NotSupportedException

a has no NumSharp array form.

title(object)

NumPy's np.char.title(a), which IS title(NDArray): each element in titlecase — a character after a cased character lowered, any other titlecased (CPython's str.title; bytes.title over ASCII letters). Any uncased character starts a new "word": '12a' becomes '12A'.

public NDArray title(object a)

Parameters

a object

The strings: an S / U / StringDType array or a text array_like (see the class remarks).

Returns

NDArray

A fresh C-ordered PLAIN array of a's dtype (a chararray operand too), 0-d for a scalar; an S / U result keeps the element width.

Exceptions

ArgumentNullException

a is null (see the class remarks).

TypeError

a is not text (string operation on non-string array); a StringDType NA whose NA object is not a str.

SystemError

A U element holding a code unit past U+10FFFF.

NotSupportedException

a has no NumSharp array form.

translate(object, object, object)

NumPy's np.char.translate(a, table, deletechars=None), which IS translate(NDArray, object, object): every character of each element mapped through table — CPython's str.translate for U and StringDType, bytes.translate for S (whose deletechars are then deleted).

public NDArray translate(object a, object table, object deletechars = null)

Parameters

a object

The strings: an S / U / StringDType array or a text array_like (see the class remarks).

table object

The table, read as the Python object it stands for and broadcast against a (see translate(NDArray, object, object)): a dict keyed by code point for U / StringDType, a 256-byte table or null for S.

deletechars object

The bytes to delete (an S operand only); null passes nothing. NumPy ignores it for U and passes it to str.translate for StringDType, which refuses it.

Returns

NDArray

A fresh C-ordered PLAIN array of a's dtype over the broadcast shape (a chararray operand too: NumPy's np.asarray drops the class), 0-d for a scalar; an S / U result keeps the element width.

Exceptions

ArgumentNullException

a is null (see the class remarks).

TypeError

a is not text (string operation on non-string array); a table or delete set of the wrong kind; deletechars with a StringDType operand (str.translate() takes exactly one argument (2 given)); a StringDType NA whose NA object is not a str.

ValueError

A mapping outside range(0x110000); an S table that is not 256 bytes long (translation table must be 256 characters long).

SystemError

A U unit past U+10FFFF that the call would keep.

IncorrectShapeException

The arguments do not broadcast.

NotSupportedException

An argument with no NumSharp array form.

upper(object)

NumPy's np.char.upper(a), which IS upper(NDArray): each element's text uppercased — CPython's str.upper (the full mappings: 'ß' becomes 'SS') for U and StringDType, bytes.upper (ASCII letters only) for S.

public NDArray upper(object a)

Parameters

a object

The strings: an S / U / StringDType array or a text array_like (see the class remarks).

Returns

NDArray

A fresh C-ordered PLAIN array of a's dtype (a chararray operand too), 0-d for a scalar. An S / U result keeps the element width, so a mapping that grows is cut: 'ß' in a U1 array becomes 'S'.

Exceptions

ArgumentNullException

a is null (see the class remarks).

TypeError

a is not text (string operation on non-string array); a StringDType NA whose NA object is not a str.

SystemError

A U element holding a code unit past U+10FFFF.

NotSupportedException

a has no NumSharp array form.

zfill(object, object)

NumPy's np.char.zfill(a, width), which IS zfill(NDArray, NDArray): each element left-filled with '0' to width characters, a leading '+' / '-' moved in front of the zeros (zfill('-42', 5) is '-0042').

public NDArray zfill(object a, object width)

Parameters

a object

The strings: an S / U / StringDType array or a text array_like.

width object

The integer widths, broadcast.

Returns

NDArray

A fresh array (for S / U at the widest result width, laid out like a; a chararray view of it for a chararray a).

Exceptions

ArgumentNullException

a or width is null.

TypeError

width is not an integer array (unsupported type <U1 for operand 'width'); a non-text operand; a uint64 width; a StringDType NA that is neither a string nor NaN-like.

ValueError

An empty broadcast.

IncorrectShapeException

The operands do not broadcast.

Operators

implicit operator DType(CharModule)

np.@char where a DType is expected: the Char dtype descriptor (NumSharp's UTF-16 code-unit dtype), the value the member held before it became the module.

public static implicit operator DType(CharModule module)

Parameters

module CharModule

The module (char).

Returns

DType

The Char descriptor, or null for a null module.