Cyforanumera
npm

API reference

String operations (np.strings / np.char)

Element-wise string operations on StringArray objects. np.strings is the modern namespace; np.char is the legacy alias (NumPy deprecated). Both operate on StringArray — a thin JS wrapper over a flat string[] with shape metadata.

NameSummary
np.strings.arrayConstruct a StringArray from a string, 1-D or 2-D nested JS string array.
np.strings.upperConvert each element to uppercase.
np.strings.lowerConvert each element to lowercase.
np.strings.capitalizeCapitalize the first character of each element; lowercase the rest.
np.strings.addElement-wise string concatenation.
np.strings.multiplyRepeat each element i times.
np.strings.equalElement-wise equality comparison.
np.strings.str_lenReturn the length of each element.

np.strings.array

#
np.char.array(data)

Construct a StringArray from a string, 1-D or 2-D nested JS string array. (Exposed under np.char.array.)

Parameters

datastring | string[] | string[][]
String data.

Returns

StringArray

Example

TypeScript
const a = np.char.array(["hello", "world"]);
a.shape;          // => [2]
a.toArray();      // => ["hello", "world"]
a.dtype;          // => "str_"
TypeScript declaration
np.char.array(data: StringLike, dtype?: StringDType | undefined): StringArray

np.strings.upper

#
np.strings.upper(a)

Convert each element to uppercase.

Parameters

aStringArray | string[]
Input string array.

Returns

StringArray

Example

TypeScript
np.strings.upper(["hello", "world"]).toArray(); // => ["HELLO", "WORLD"]
TypeScript declaration
np.strings.upper(a: StringLike): StringArray

np.strings.lower

#
np.strings.lower(a)

Convert each element to lowercase.

Parameters

aStringArray | string[]
Input string array.

Returns

StringArray

Example

TypeScript
np.strings.lower(["HELLO", "WORLD"]).toArray(); // => ["hello", "world"]
TypeScript declaration
np.strings.lower(a: StringLike): StringArray

np.strings.capitalize

#
np.strings.capitalize(a)

Capitalize the first character of each element; lowercase the rest.

Parameters

aStringArray | string[]
Input string array.

Returns

StringArray

Example

TypeScript
np.strings.capitalize(["hello WORLD"]).toArray(); // => ["Hello world"]
TypeScript declaration
np.strings.capitalize(a: StringLike): StringArray

np.strings.add

#
np.strings.add(a, b)

Element-wise string concatenation.

Parameters

aStringArray | string[]
Left operand.
bStringArray | string[]
Right operand.

Returns

StringArray

Example

TypeScript
np.strings.add(["hello"], [" world"]).toArray(); // => ["hello world"]
TypeScript declaration
np.strings.add(a: StringLike, b: StringLike): StringArray

np.strings.multiply

#
np.strings.multiply(a, i)

Repeat each element i times.

Parameters

aStringArray | string[]
Input string array.
inumber
Repetition count.

Returns

StringArray

Example

TypeScript
np.strings.multiply(["ab"], 3).toArray(); // => ["ababab"]
TypeScript declaration
np.strings.multiply(a: StringLike, i: number | NDArray): StringArray

np.strings.equal

#
np.strings.equal(a, b)

Element-wise equality comparison.

Parameters

aStringArray | string[]
Left operand.
bStringArray | string[]
Right operand.

Returns

NDArray (bool)

Example

TypeScript
np.strings.equal(["abc", "xyz"], ["abc", "abc"]).toArray(); // => [true, false]
TypeScript declaration
np.strings.equal(a: StringLike, b: StringLike): NDArray

np.strings.str_len

#
np.strings.str_len(a)

Return the length of each element.

Parameters

aStringArray | string[]
Input string array.

Returns

NDArray (int64)

Example

TypeScript
np.strings.str_len(["hello", "hi"]).toArray(); // => [5, 2]
TypeScript declaration
np.strings.str_len(a: StringLike): NDArray