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.
| Name | Summary |
|---|---|
np.strings.array | Construct a StringArray from a string, 1-D or 2-D nested JS string array. |
np.strings.upper | Convert each element to uppercase. |
np.strings.lower | Convert each element to lowercase. |
np.strings.capitalize | Capitalize the first character of each element; lowercase the rest. |
np.strings.add | Element-wise string concatenation. |
np.strings.multiply | Repeat each element i times. |
np.strings.equal | Element-wise equality comparison. |
np.strings.str_len | Return 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.)
NumPynumpy.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): StringArraynp.strings.upper
#np.strings.upper(a)
Convert each element to uppercase.
NumPynumpy.strings.upper
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): StringArraynp.strings.lower
#np.strings.lower(a)
Convert each element to lowercase.
NumPynumpy.strings.lower
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): StringArraynp.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): StringArraynp.strings.add
#np.strings.add(a, b)
Element-wise string concatenation.
NumPynumpy.strings.add
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): StringArraynp.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): StringArraynp.strings.equal
#np.strings.equal(a, b)
Element-wise equality comparison.
NumPynumpy.strings.equal
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): NDArraynp.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