Cyforanumera
npm

API reference

Record arrays (np.rec)

Lightweight structured record arrays as named NDArray columns. np.recarray is the class constructor; np.rec is the module namespace.

NameSummary
np.recarrayCreate a zero-filled record array with named fields.
np.fromarraysBuild a record array from a list of column arrays.
np.fromrecordsBuild a record array from a list of row tuples.
np.rec.arrayFlexible record array constructor.
np.find_duplicateReturn values that appear more than once in list.

np.recarray

#
new np.rec.recarray(shape, {names, formats})

Create a zero-filled record array with named fields. np.recarray is also exported at the top level.

Parameters

shapenumber | number[]
Number of records, or shape array.
[options.names]string | string[]
Field names.
[options.formats]string | string[]
Format strings (e.g. "float64", "i4").

Returns

recarray

Example

TypeScript
const r = new np.rec.recarray(3, { names: ["x", "y"], formats: ["float64", "int32"] });
r.field("x").shape; // => [3]
r.field("y").dtype.name; // => "int32"
TypeScript declaration
new np.recarray(shape: number | number[], opts?: RecArrayOptions | undefined)
new np.rec.recarray(shape: number | number[], opts?: RecArrayOptions | undefined)

np.fromarrays

#
np.rec.fromarrays(arrayList, {names, formats})

Build a record array from a list of column arrays.

Parameters

arrayListArrayLike[]
One array per field.
[options.names]string | string[]
Field names.
[options.formats]string | string[]
Optional format strings.

Returns

recarray

Example

TypeScript
const r = np.rec.fromarrays([np.array([1, 2, 3]), np.array([4.0, 5.0, 6.0])], { names: ["x", "y"] });
r.field("x").toArray(); // => [1, 2, 3]
r.field("y").toArray(); // => [4, 5, 6]
TypeScript declaration
np.rec.fromarrays(arrayList: ArrayLike[], opts?: RecArrayOptions | undefined): recarray

np.fromrecords

#
np.rec.fromrecords(recList, {names, formats})

Build a record array from a list of row tuples.

Parameters

recListunknown[][]
Array of rows.
[options.names]string | string[]
Field names.

Returns

recarray

Example

TypeScript
const r = np.rec.fromrecords([[1, 2], [3, 4]], { names: ["a", "b"] });
r.field("a").toArray(); // => [1, 3]
r.field("b").toArray(); // => [2, 4]
TypeScript declaration
np.rec.fromrecords(recList: ArrayLike | unknown[][], opts?: RecArrayOptions | undefined): recarray

np.rec.array

#
np.rec.array(obj, {names, formats})

Flexible record array constructor. Delegates to fromarrays, fromrecords, or clones an existing recarray.

Parameters

objrecarray | ArrayLike[] | unknown[][]
Source data.
[options]RecArrayOptions
Names, formats.

Returns

recarray

Example

TypeScript
const r = np.rec.array([[1, 2.0], [3, 4.0]], { names: "a,b" });
r.field("a").toArray(); // => [1, 3]
TypeScript declaration
np.rec.array(obj: recarray | ArrayLike[] | unknown[][], opts?: RecArrayOptions | undefined): recarray

np.find_duplicate

#
np.rec.find_duplicate(list)

Return values that appear more than once in list.

Parameters

listunknown[]
Input list.

Returns

unknown[]

Example

TypeScript
np.rec.find_duplicate([1, 2, 1, 3, 2]); // => [1, 2]
TypeScript declaration
np.rec.find_duplicate(list: unknown[]): unknown[]