function cumprod
cumprod(x: array): array

Cumulative product of array elements.

Computes the cumulative product of elements in an array or matrix along a specified dimension.

Examples

Cumulative product of a 1D array

import { assertEquals } from "jsr:@std/assert";

assertEquals(cumprod([5, 6, 3]), [5, 30, 90]);

Cumulative product of a matrix along columns (dim=1)

import { assertEquals } from "jsr:@std/assert";

assertEquals(cumprod([[5, 6, 5], [7, 8, -1]], 1), [[5, 35], [6, 48], [5, -5]]);

Cumulative product of a matrix along rows (dim=0)

import { assertEquals } from "jsr:@std/assert";

assertEquals(cumprod([[5, 6, 5], [7, 8, -1]], 0), [[5, 30, 150], [7, 56, -56]]);

Parameters

The input array or matrix of values

Return Type

The cumulative product of the input values

Throws

If no input is provided

cumprod(
x: array,
dim: 0,
): array

Cumulative product of array elements.

Computes the cumulative product of elements in an array or matrix along a specified dimension.

Examples

Cumulative product of a 1D array

import { assertEquals } from "jsr:@std/assert";

assertEquals(cumprod([5, 6, 3]), [5, 30, 90]);

Cumulative product of a matrix along columns (dim=1)

import { assertEquals } from "jsr:@std/assert";

assertEquals(cumprod([[5, 6, 5], [7, 8, -1]], 1), [[5, 35], [6, 48], [5, -5]]);

Cumulative product of a matrix along rows (dim=0)

import { assertEquals } from "jsr:@std/assert";

assertEquals(cumprod([[5, 6, 5], [7, 8, -1]], 0), [[5, 30, 150], [7, 56, -56]]);

Parameters

The input array or matrix of values

dim: 0

The dimension along which to calculate, 1 for columns, 0 for rows (defaults to 1)

Return Type

The cumulative product of the input values

Throws

If no input is provided

cumprod(
x: array,
dim: 1,
): array

Cumulative product of array elements.

Computes the cumulative product of elements in an array or matrix along a specified dimension.

Examples

Cumulative product of a 1D array

import { assertEquals } from "jsr:@std/assert";

assertEquals(cumprod([5, 6, 3]), [5, 30, 90]);

Cumulative product of a matrix along columns (dim=1)

import { assertEquals } from "jsr:@std/assert";

assertEquals(cumprod([[5, 6, 5], [7, 8, -1]], 1), [[5, 35], [6, 48], [5, -5]]);

Cumulative product of a matrix along rows (dim=0)

import { assertEquals } from "jsr:@std/assert";

assertEquals(cumprod([[5, 6, 5], [7, 8, -1]], 0), [[5, 30, 150], [7, 56, -56]]);

Parameters

The input array or matrix of values

dim: 1

The dimension along which to calculate, 1 for columns, 0 for rows (defaults to 1)

Return Type

The cumulative product of the input values

Throws

If no input is provided

cumprod(
x: matrix,
dim: 0,
): matrix

Cumulative product of array elements.

Computes the cumulative product of elements in an array or matrix along a specified dimension.

Examples

Cumulative product of a 1D array

import { assertEquals } from "jsr:@std/assert";

assertEquals(cumprod([5, 6, 3]), [5, 30, 90]);

Cumulative product of a matrix along columns (dim=1)

import { assertEquals } from "jsr:@std/assert";

assertEquals(cumprod([[5, 6, 5], [7, 8, -1]], 1), [[5, 35], [6, 48], [5, -5]]);

Cumulative product of a matrix along rows (dim=0)

import { assertEquals } from "jsr:@std/assert";

assertEquals(cumprod([[5, 6, 5], [7, 8, -1]], 0), [[5, 30, 150], [7, 56, -56]]);

Parameters

The input array or matrix of values

dim: 0

The dimension along which to calculate, 1 for columns, 0 for rows (defaults to 1)

Return Type

The cumulative product of the input values

Throws

If no input is provided

cumprod(
x: matrix,
dim: 1,
): matrix

Cumulative product of array elements.

Computes the cumulative product of elements in an array or matrix along a specified dimension.

Examples

Cumulative product of a 1D array

import { assertEquals } from "jsr:@std/assert";

assertEquals(cumprod([5, 6, 3]), [5, 30, 90]);

Cumulative product of a matrix along columns (dim=1)

import { assertEquals } from "jsr:@std/assert";

assertEquals(cumprod([[5, 6, 5], [7, 8, -1]], 1), [[5, 35], [6, 48], [5, -5]]);

Cumulative product of a matrix along rows (dim=0)

import { assertEquals } from "jsr:@std/assert";

assertEquals(cumprod([[5, 6, 5], [7, 8, -1]], 0), [[5, 30, 150], [7, 56, -56]]);

Parameters

The input array or matrix of values

dim: 1

The dimension along which to calculate, 1 for columns, 0 for rows (defaults to 1)

Return Type

The cumulative product of the input values

Throws

If no input is provided