GitHub
deepbox/ndarray

Shape, Indexing & Set Ops

Indexing, slicing, reshaping, stacking, insertion, deletion, and set-style array operations.
Indexing
Manipulation
type columnStack
export declare const columnStack: typeof column_stack;
columnStack is a public const in deepbox/ndarray.
type SliceRange
export type SliceRange = number | { readonly start?: number; readonly end?: number; readonly step?: number; };
A single index or a start/end/step range for tensor slicing.
type expandDims
export declare const expandDims: typeof unsqueeze;
expandDims is a public const in deepbox/ndarray.
column_stack
export declare function column_stack(tensors: Tensor[]): Tensor;

Stack 1D arrays as columns into a 2D array.

concatenate
export declare function concatenate(tensors: Tensor[], axis?: Axis): Tensor;

Concatenate tensors along an existing axis.

delete_
export declare function delete_(t: Tensor, indices: number | number[], axis?: Axis): Tensor;

Delete elements from a tensor along an axis.

digitize
export declare function digitize(x: Tensor, bins: Tensor, right?: boolean): Tensor;

Return the indices of the bins to which each value in the input array belongs.

gcd
export declare function gcd(a: Tensor, b: Tensor): Tensor;

Element-wise greatest common divisor.

gradient
export declare function gradient(f: Tensor, spacing?: number | Tensor): Tensor;

Return the numerical gradient of a 1D array using central finite differences.

hstack
export declare function hstack(tensors: Tensor[]): Tensor;

Stack tensors horizontally (column-wise).

insert
export declare function insert(t: Tensor, indices: number | number[], values: number | Tensor, axis?: Axis): Tensor;

Insert values into a tensor along an axis before given indices.

interp
export declare function interp(x: Tensor, xp: Tensor, fp: Tensor, left?: number, right?: number): Tensor;

One-dimensional linear interpolation.

intersect1d
export declare function intersect1d(a: Tensor, b: Tensor): Tensor;

Compute the sorted, unique intersection of two 1D tensors.

lcm
export declare function lcm(a: Tensor, b: Tensor): Tensor;

Element-wise least common multiple.

repeat
export declare function repeat(t: Tensor, repeats: number, axis?: Axis): Tensor;

Repeat elements of a tensor along an axis.

setdiff1d
export declare function setdiff1d(a: Tensor, b: Tensor): Tensor;

Compute the sorted set difference of two 1D tensors.

split
export declare function split(t: Tensor, indices_or_sections: number | number[], axis?: Axis): Tensor[];

Split tensor into multiple sub-tensors along an axis.

stack
export declare function stack(tensors: Tensor[], axis?: Axis): Tensor;

Stack tensors along a new axis.

tile
export declare function tile(t: Tensor, reps: number[]): Tensor;

Repeat tensor along axes by tiling.

trapz
export declare function trapz(y: Tensor, x?: Tensor, dx?: number): number;

Integrate along the given axis using the composite trapezoidal rule.

union1d
export declare function union1d(a: Tensor, b: Tensor): Tensor;

Compute the sorted, unique union of two 1D tensors.

vstack
export declare function vstack(tensors: Tensor[]): Tensor;

Stack tensors vertically (row-wise).

flatten
export declare function flatten(t: Tensor): Tensor;

Flatten to 1D.

gather
export declare function gather(t: Tensor, indices: Tensor, axis: Axis): Tensor;

Gather values along an axis specified by indices.

reshape
export declare function reshape(t: Tensor, rawShape: Shape): Tensor;

Change shape (view) without copying.

slice
export declare function slice(t: Tensor, ...ranges: SliceRange[]): Tensor;

Slice a tensor.

transpose
export declare function transpose(t: Tensor, axes?: readonly number[]): Tensor;

Transpose tensor dimensions.

squeeze
export declare function squeeze(t: Tensor, axis?: Axis | Axis[]): Tensor;

Remove single-dimensional entries from the shape.

unsqueeze
export declare function unsqueeze(t: Tensor, axis: number): Tensor;

Expand the shape by inserting a new axis.

ndarray-shape.ts
import {  concatenate,  delete_,  hstack,  insert,  meshgrid,  repeat,  reshape,  slice,  split,  stack,  tensor,  tile,  union1d,} from "deepbox/ndarray";const x = tensor([[1, 2, 3], [4, 5, 6]]);console.log(slice(x, { start: 0, end: 2 }, { start: 1, end: 3 }).toString());console.log(reshape(x, [3, 2]).toString());console.log(stack([tensor([1, 2]), tensor([3, 4])]).toString());console.log(concatenate([tensor([1, 2]), tensor([3, 4])]).toString());console.log(split(tensor([1, 2, 3, 4]), 2).map((t) => t.toString()));console.log(repeat(tensor([1, 2]), 2).toString());console.log(tile(tensor([[1, 2]]), [2, 1]).toString());console.log(insert(tensor([1, 3, 4]), 1, tensor([2])).toString());console.log(delete_(tensor([1, 2, 3, 4]), 2).toString());console.log(hstack([tensor([[1], [2]]), tensor([[3], [4]])]).toString());console.log(meshgrid(tensor([0, 1]), tensor([10, 20])).map((t) => t.toString()));console.log(union1d(tensor([1, 2, 3]), tensor([3, 4, 5])).toString());