Overview
numpy-ts supports 13 data types that mirror NumPy’s numeric type system. Every NDArray has a single dtype that determines how its elements are stored in memory and how arithmetic behaves.Supported dtypes
Default dtype
When you create an array without specifying a dtype, numpy-ts usesfloat64, matching NumPy:
Creating arrays with specific dtypes
Pass thedtype option to any creation function:
BigInt for int64 and uint64
JavaScriptnumber only has 53 bits of integer precision. For full 64-bit integer support, numpy-ts uses BigInt64Array and BigUint64Array under the hood. This means int64 and uint64 arrays exchange values as bigint, not number.
Complex numbers
numpy-ts provides aComplex class for complex number support, with two complex dtypes:
complex128— each element is a pair offloat64values (real, imaginary)complex64— each element is a pair offloat32values (real, imaginary)
Complex class supports arithmetic:
Type promotion hierarchy
When you combine arrays with different dtypes in an operation, numpy-ts promotes to a common type that can represent both without data loss. The promotion follows NumPy’s rules:Integer overflow and wrapping
Integer dtypes wrap on overflow, just like NumPy and C integer types. There is no error or automatic promotion:If you need overflow protection, use a wider dtype (
int16 instead of int8) or promote to float64 first.Converting dtypes with astype()
Use astype() to create a new array with a different dtype:
astype() always returns a copy. Pass copy: false to return the same array when the dtype already matches:
Special cases
Comparisons always return bool
Regardless of input dtypes, comparison operations always produce bool arrays:
mean() promotes integers to float64
Just like NumPy, mean() converts integer arrays to float64 to avoid truncation:
Boolean arrays
Boolean arrays store0 (false) and 1 (true) as uint8 values. They participate in arithmetic as integers:
Next steps
Array Basics
NDArray properties, creation, and conversion.
Broadcasting
How arrays with different shapes combine in operations.