Cyforanumera
npm

API reference

Data types

Supported: bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, complex64 and complex128. Each one is available as np.<name>, and anywhere a DTypeLike is accepted you can pass the name as a string. NumPy aliases float, double, single, half, int, complex and bool_ are also accepted.

NameSummary
np.dtypeResolves a name or DType to the canonical DType singleton, which has name, kind (b/i/u/f/c), itemSize and alignment.
np.promoteTypesThe smallest dtype that both inputs can be safely cast to, using NumPy's promotion table.
np.canCastWhether from can be cast to to under a NumPy casting rule: "no", "equiv", "safe" (the default), "same_kind" or "unsafe".
np.finfoMachine limits of a float dtype (complex: of its component).
np.iinfoLimits of an integer dtype: bits, min, max, dtype, kind; min/max are numbers (lossy beyond 2^53) and minExact/maxExact exact bigints.
np.resultTypeThe dtype NumPy's type promotion gives.
np.minScalarTypeThe smallest dtype that holds the value of a JS scalar or a 0-d array (unsigned integers preferred for non-negative values; floats sized by NumPy's thresholds).
np.issubdtypeWhether a is b (concrete dtype) or descends from the abstract dtype b (np.generic, np.number, np.integer, np.signedinteger, np.unsignedinteger, np.inexact, np.floating, np.complexfloating).
np.isdtypeArray API dtype test.
np.commonTypeThe float or complex dtype all inputs convert to (integers count as float64; bool raises DTypeError).
np.mintypecodeNumPy's smallest-size type character from typeset among typechars (a string of type characters or a list of characters, DTypes or arrays).
np.genericAbstract dtype (NumPy's scalar type hierarchy, parent: null), for issubdtype.
np.numberAbstract dtype (NumPy's scalar type hierarchy, parent: generic), for issubdtype.
np.integerAbstract dtype (NumPy's scalar type hierarchy, parent: number), for issubdtype.
np.signedintegerAbstract dtype (NumPy's scalar type hierarchy, parent: integer), for issubdtype.
np.unsignedintegerAbstract dtype (NumPy's scalar type hierarchy, parent: integer), for issubdtype.
np.inexactAbstract dtype (NumPy's scalar type hierarchy, parent: number), for issubdtype.
np.floatingAbstract dtype (NumPy's scalar type hierarchy, parent: inexact), for issubdtype.
np.complexfloatingAbstract dtype (NumPy's scalar type hierarchy, parent: inexact), for issubdtype.
np.int_Default Python integer dtype: int64 on 64-bit platforms.
np.intcC int dtype: int32.
np.intpPointer-sized signed integer dtype: int64 on 64-bit platforms.
np.shortC short dtype: int16.
np.byteC signed char dtype: int8.
np.ubyteC unsigned char dtype: uint8.
np.ushortC unsigned short dtype: uint16.
np.uintPlatform unsigned integer dtype: uint64 on 64-bit platforms.
np.uintcC unsigned int dtype: uint32.
np.uintpPointer-sized unsigned integer dtype: uint64 on 64-bit platforms.
np.ulongC unsigned long dtype: uint64 on 64-bit platforms.
np.doubleDouble-precision float dtype: float64.
np.singleSingle-precision float dtype: float32.
np.halfHalf-precision float dtype: float16.
np.cdoubleDouble-precision complex dtype: complex128.
np.csingleSingle-precision complex dtype: complex64.
np.longdoubleLong double dtype: aliased to float64 (no 80-bit float in JS).
np.clongdoubleLong double complex dtype: aliased to complex128 (no 80-bit complex in JS).
np.bytes_Byte-string dtype sentinel (string literal "bytes").
np.str_Unicode-string dtype sentinel (string literal "str").
np.datetime64Construct a datetime64 scalar from an ISO-8601 string, integer epoch offset, or another DatetimeArray.
np.timedelta64Construct a timedelta64 scalar from an integer duration and unit.
np.datetime_dataReturns the unit and count for a datetime64 or timedelta64 dtype.
np.datetime_as_stringConvert a DatetimeArray to ISO-8601 string(s).

np.dtype

#
np.dtype(like)

Resolves a name or DType to the canonical DType singleton, which has name, kind (b/i/u/f/c), itemSize and alignment. Unknown names throw DTypeError.

Parameters

likeDTypeLike
Name, alias or DType.

Returns

DType

Example

TypeScript
const d = np.dtype("single");
d.name;              // => "float32"
d.kind;              // => "f"
d.itemSize;          // => 4
d === np.float32;    // => true
TypeScript declaration
np.dtype(like: DTypeLike): DType

np.promoteTypes

#
np.promoteTypes(a, b)

The smallest dtype that both inputs can be safely cast to, using NumPy's promotion table.

Parameters

a, bDTypeLike
Input dtypes.

Returns

DType

Example

TypeScript
np.promoteTypes("int32", "float32").name; // => "float64"
np.promoteTypes("uint8", "int8").name;    // => "int16"
TypeScript declaration
np.promoteTypes(a: DTypeLike, b: DTypeLike): DType

np.canCast

#
np.canCast(from, to, casting = "safe")

Whether from can be cast to to under a NumPy casting rule: "no", "equiv", "safe" (the default), "same_kind" or "unsafe". from can be a dtype or an array, in which case only its dtype is used. JS numbers raise DTypeError, as Python scalars do in NumPy 2. An unknown rule raises ValueError.

Parameters

fromDTypeLike | NDArray
Source dtype, or an array whose dtype is used.
toDTypeLike
Target dtype.
castingstring
Casting rule.

Returns

boolean

Example

TypeScript
np.canCast("int8", "int16");                   // => true
np.canCast("float64", "float32");              // => false
np.canCast("float64", "float32", "same_kind"); // => true
np.canCast("int64", "uint8", "same_kind");     // => false
TypeScript declaration
np.canCast(from: DTypeLike | { readonly dtype: DType; }, to: DTypeLike, casting?: Casting | undefined): boolean

np.finfo

#
np.finfo(dtype | array)

Machine limits of a float dtype (complex: of its component). Fields as NumPy in camelCase: bits, eps, epsneg, max, min, tiny, smallestNormal, smallestSubnormal, resolution, precision, iexp, nexp, nmant, machep, negep, minexp, maxexp, dtype. Values are JS numbers holding the dtype's value. Non-float dtypes raise ValueError.

Returns

FInfo

Example

TypeScript
np.finfo("float16").max;  // => 65504
np.finfo("float32").nmant; // => 23
np.finfo("float64").eps;   // => 2.220446049250313e-16
TypeScript declaration
np.finfo(dt: NDArray | DTypeLike): FInfo

np.iinfo

#
np.iinfo(dtype | array)

Limits of an integer dtype: bits, min, max, dtype, kind; min/max are numbers (lossy beyond 2^53) and minExact/maxExact exact bigints. Non-integer dtypes raise ValueError.

Returns

IInfo

Example

TypeScript
np.iinfo("int8").min;   // => -128
np.iinfo("uint16").max; // => 65535
np.iinfo("uint64").maxExact === 18446744073709551615n; // => true
TypeScript declaration
np.iinfo(dt: NDArray | DTypeLike): IInfo

np.resultType

#
np.resultType(...arraysAndDtypes)

The dtype NumPy's type promotion gives. DTypes, dtype names and arrays are promoted with promoteTypes; JS scalars are weak (NEP 50): they can raise the kind (int → float → complex) but not the size.

Returns

DType

Example

TypeScript
np.resultType("int8", 300).name;          // => "int8"
np.resultType("int8", 1.5).name;          // => "float64"
np.resultType("float32", np.complex(0, 1)).name; // => "complex64"
np.resultType("int8", "uint8").name;      // => "int16"
TypeScript declaration
np.resultType(...args: (NDArray | NestedArray | DTypeLike)[]): DType

np.minScalarType

#
np.minScalarType(x)

The smallest dtype that holds the value of a JS scalar or a 0-d array (unsigned integers preferred for non-negative values; floats sized by NumPy's thresholds). Arrays with ndim > 0 return their dtype. JS numbers count as integers only when they are safe integers; use a bigint beyond 2^53.

Returns

DType

Example

TypeScript
np.minScalarType(10).name;   // => "uint8"
np.minScalarType(-129).name; // => "int16"
np.minScalarType(3.1).name;  // => "float16"
np.minScalarType(1e50).name; // => "float64"
TypeScript declaration
np.minScalarType(a: NDArray | JSScalar): DType

np.issubdtype

#
np.issubdtype(a, b)

Whether a is b (concrete dtype) or descends from the abstract dtype b (np.generic, np.number, np.integer, np.signedinteger, np.unsignedinteger, np.inexact, np.floating, np.complexfloating).

Returns

boolean

Example

TypeScript
np.issubdtype("float32", np.floating); // => true
np.issubdtype("bool", np.integer);     // => false
np.issubdtype("int8", "int16");        // => false
TypeScript declaration
np.issubdtype(a: DTypeLike | AbstractDType, b: DTypeLike | AbstractDType): boolean

np.isdtype

#
np.isdtype(dtype, kind)

Array API dtype test. kind is a DType, one of "bool", "signed integer", "unsigned integer", "integral", "real floating", "complex floating", "numeric", or an array of these. dtype must be a DType object.

Returns

boolean

Example

TypeScript
np.isdtype(np.float64, "real floating");          // => true
np.isdtype(np.int8, ["bool", "unsigned integer"]); // => false
np.isdtype(np.bool, "numeric");                    // => false
TypeScript declaration
np.isdtype(dt: DType, kind: string | DType | readonly (string | DType)[]): boolean

np.commonType

#
np.commonType(...arrays)

The float or complex dtype all inputs convert to (integers count as float64; bool raises DTypeError). NumPy returns a scalar type; this returns a DType.

Returns

DType

Example

TypeScript
np.commonType(np.arange(3)).name; // => "float64"
np.commonType(np.zeros([1], { dtype: "float32" }), np.zeros([1], { dtype: "complex64" })).name; // => "complex64"
TypeScript declaration
np.commonType(...arrays: (NDArray | NestedArray)[]): DType

np.mintypecode

#
np.mintypecode(typechars, typeset = "GDFgdf", default = "d")

NumPy's smallest-size type character from typeset among typechars (a string of type characters or a list of characters, DTypes or arrays). F with d gives D.

Returns

string

Example

TypeScript
np.mintypecode(["d", "f"]); // => "d"
np.mintypecode("dF");       // => "D"
np.mintypecode("i");        // => "d"
TypeScript declaration
np.mintypecode(typechars: string | readonly (string | NDArray | NestedArray | DType)[], typeset?: string | undefined, defaultCode?: string | undefined): string

np.generic

#
np.generic

Abstract dtype (NumPy's scalar type hierarchy, parent: null), for issubdtype. Not usable as an array dtype.

Returns

AbstractDType

Example

TypeScript
np.issubdtype("float32", np.generic); // => true

np.number

#
np.number

Abstract dtype (NumPy's scalar type hierarchy, parent: generic), for issubdtype. Not usable as an array dtype.

Returns

AbstractDType

Example

TypeScript
np.issubdtype("float32", np.number); // => true

np.integer

#
np.integer

Abstract dtype (NumPy's scalar type hierarchy, parent: number), for issubdtype. Not usable as an array dtype.

Returns

AbstractDType

Example

TypeScript
np.issubdtype("float32", np.integer); // => false

np.signedinteger

#
np.signedinteger

Abstract dtype (NumPy's scalar type hierarchy, parent: integer), for issubdtype. Not usable as an array dtype.

Returns

AbstractDType

Example

TypeScript
np.issubdtype("float32", np.signedinteger); // => false

np.unsignedinteger

#
np.unsignedinteger

Abstract dtype (NumPy's scalar type hierarchy, parent: integer), for issubdtype. Not usable as an array dtype.

Returns

AbstractDType

Example

TypeScript
np.issubdtype("float32", np.unsignedinteger); // => false

np.inexact

#
np.inexact

Abstract dtype (NumPy's scalar type hierarchy, parent: number), for issubdtype. Not usable as an array dtype.

Returns

AbstractDType

Example

TypeScript
np.issubdtype("float32", np.inexact); // => true

np.floating

#
np.floating

Abstract dtype (NumPy's scalar type hierarchy, parent: inexact), for issubdtype. Not usable as an array dtype.

Returns

AbstractDType

Example

TypeScript
np.issubdtype("float32", np.floating); // => true

np.complexfloating

#
np.complexfloating

Abstract dtype (NumPy's scalar type hierarchy, parent: inexact), for issubdtype. Not usable as an array dtype.

Returns

AbstractDType

Example

TypeScript
np.issubdtype("float32", np.complexfloating); // => false

np.int_

#
np.int_

Default Python integer dtype: int64 on 64-bit platforms.

Returns

DType

Example

TypeScript
np.int_.name; // => "int64"
TypeScript declaration
np.int_: DType

np.intc

#
np.intc

C int dtype: int32.

Returns

DType

Example

TypeScript
np.intc.name; // => "int32"
TypeScript declaration
np.intc: DType

np.intp

#
np.intp

Pointer-sized signed integer dtype: int64 on 64-bit platforms.

Returns

DType

Example

TypeScript
np.intp.name; // => "int64"
TypeScript declaration
np.intp: DType

np.short

#
np.short

C short dtype: int16.

Returns

DType

Example

TypeScript
np.short.name; // => "int16"
TypeScript declaration
np.short: DType

np.byte

#
np.byte

C signed char dtype: int8.

Returns

DType

Example

TypeScript
np.byte.name; // => "int8"
TypeScript declaration
np.byte: DType

np.ubyte

#
np.ubyte

C unsigned char dtype: uint8.

Returns

DType

Example

TypeScript
np.ubyte.name; // => "uint8"
TypeScript declaration
np.ubyte: DType

np.ushort

#
np.ushort

C unsigned short dtype: uint16.

Returns

DType

Example

TypeScript
np.ushort.name; // => "uint16"
TypeScript declaration
np.ushort: DType

np.uint

#
np.uint

Platform unsigned integer dtype: uint64 on 64-bit platforms.

Returns

DType

Example

TypeScript
np.uint.name; // => "uint64"
TypeScript declaration
np.uint: DType

np.uintc

#
np.uintc

C unsigned int dtype: uint32.

Returns

DType

Example

TypeScript
np.uintc.name; // => "uint32"
TypeScript declaration
np.uintc: DType

np.uintp

#
np.uintp

Pointer-sized unsigned integer dtype: uint64 on 64-bit platforms.

Returns

DType

Example

TypeScript
np.uintp.name; // => "uint64"
TypeScript declaration
np.uintp: DType

np.ulong

#
np.ulong

C unsigned long dtype: uint64 on 64-bit platforms.

Returns

DType

Example

TypeScript
np.ulong.name; // => "uint64"
TypeScript declaration
np.ulong: DType

np.double

#
np.double

Double-precision float dtype: float64.

Returns

DType

Example

TypeScript
np.double.name; // => "float64"
TypeScript declaration
np.double: DType

np.single

#
np.single

Single-precision float dtype: float32.

Returns

DType

Example

TypeScript
np.single.name; // => "float32"
TypeScript declaration
np.single: DType

np.half

#
np.half

Half-precision float dtype: float16.

Returns

DType

Example

TypeScript
np.half.name; // => "float16"
TypeScript declaration
np.half: DType

np.cdouble

#
np.cdouble

Double-precision complex dtype: complex128.

Returns

DType

Example

TypeScript
np.cdouble.name; // => "complex128"
TypeScript declaration
np.cdouble: DType

np.csingle

#
np.csingle

Single-precision complex dtype: complex64.

Returns

DType

Example

TypeScript
np.csingle.name; // => "complex64"
TypeScript declaration
np.csingle: DType

np.longdouble

#
np.longdouble

Long double dtype: aliased to float64 (no 80-bit float in JS).

Returns

DType

Example

TypeScript
np.longdouble.name; // => "float64"

np.clongdouble

#
np.clongdouble

Long double complex dtype: aliased to complex128 (no 80-bit complex in JS).

Returns

DType

Example

TypeScript
np.clongdouble.name; // => "complex128"

np.bytes_

#
np.bytes_

Byte-string dtype sentinel (string literal "bytes"). In NumPy, bytes_ is the fixed-width byte-string dtype; in numera it is a string tag for dtype-aware APIs.

Returns

"bytes"

Example

TypeScript
np.bytes_; // => "bytes"
TypeScript declaration
np.bytes_: "bytes"

np.str_

#
np.str_

Unicode-string dtype sentinel (string literal "str"). In NumPy, str_ is the fixed-width unicode dtype; in numera it is a string tag for dtype-aware APIs.

Returns

"str"

Example

TypeScript
np.str_; // => "str"
TypeScript declaration
np.str_: "str"

np.datetime64

#
np.datetime64(value, [unit])

Construct a datetime64 scalar from an ISO-8601 string, integer epoch offset, or another DatetimeArray. The returned DatetimeArray holds int64 epoch offsets and a unit string.

Parameters

valuestring | number | bigint | DatetimeArray
ISO-8601 string (e.g. "2023-01-15") or integer epoch offset.
[unit]string
Datetime unit: "Y" "M" "W" "D" "h" "m" "s" "ms" "us" "ns". Inferred from the string when omitted.

Returns

DatetimeArray — a 0-d datetime64 array.

Example

TypeScript
np.datetime64("2023-01-15").unit; // => "D"
TypeScript declaration
np.datetime64(value: DatetimeInput, unit?: string | undefined): DatetimeArray

np.timedelta64

#
np.timedelta64(value, [unit])

Construct a timedelta64 scalar from an integer duration and unit.

Parameters

valuenumber | bigint | TimedeltaArray
Duration value.
[unit]string
Time unit (same set as datetime64). Defaults to "s".

Returns

TimedeltaArray — a 0-d timedelta64 array.

Example

TypeScript
np.timedelta64(5, "D").unit; // => "D"
TypeScript declaration
np.timedelta64(value: TimedeltaInput, unit?: string | undefined): TimedeltaArray

np.datetime_data

#
np.datetime_data(dtype)

Returns the unit and count for a datetime64 or timedelta64 dtype. The count is always 1.

Parameters

dtypeDatetimeDType | TimedeltaDType | DatetimeArray | TimedeltaArray
A datetime or timedelta dtype or array.

Returns

[unit, count] — a tuple `[string, 1]`.

Example

TypeScript
np.datetime_data(np.datetime64("2023-01-15"))[0]; // => "D"

np.datetime_as_string

#
np.datetime_as_string(arr, [options])

Convert a DatetimeArray to ISO-8601 string(s). Optionally truncate to a coarser unit.

Parameters

arrDatetimeArray
The datetime array to format.
[options.unit]string
Output unit (truncates to this resolution). Defaults to the array's own unit.
[options.timezone]string
Timezone hint (accepted, not applied; all output is UTC).

Returns

string | string[] — one string per element.

Example

TypeScript
np.datetime_as_string(np.datetime64("2023-01-15")); // => "2023-01-15"
TypeScript declaration
np.datetime_as_string(arr: DatetimeArray, options?: string | DatetimeAsStringOptions | undefined): string | string[]