function prod
prod(x: array): number

Product of array elements.

Computes the product of elements in an array or matrix. Optionally, computes the product along a specified dimension.

Examples

Product of a vector

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

assertEquals(prod([5, 6, 3]), 90);

Product of matrix elements along rows

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

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

Product of matrix elements along columns

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

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

Parameters

The input array or matrix of values

Return Type

number

The product of the array elements, or an array of products if a matrix is provided

Throws

If no input arguments are provided

prod(
x: array,
dim: 0,
): number

Product of array elements.

Computes the product of elements in an array or matrix. Optionally, computes the product along a specified dimension.

Examples

Product of a vector

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

assertEquals(prod([5, 6, 3]), 90);

Product of matrix elements along rows

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

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

Product of matrix elements along columns

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

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

Parameters

The input array or matrix of values

dim: 0

The dimension to operate along, 1 for columns, 0 for rows (default is 1)

Return Type

number

The product of the array elements, or an array of products if a matrix is provided

Throws

If no input arguments are provided

prod(
x: array,
dim: 1,
): number

Product of array elements.

Computes the product of elements in an array or matrix. Optionally, computes the product along a specified dimension.

Examples

Product of a vector

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

assertEquals(prod([5, 6, 3]), 90);

Product of matrix elements along rows

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

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

Product of matrix elements along columns

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

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

Parameters

The input array or matrix of values

dim: 1

The dimension to operate along, 1 for columns, 0 for rows (default is 1)

Return Type

number

The product of the array elements, or an array of products if a matrix is provided

Throws

If no input arguments are provided

prod(
x: matrix,
dim: 0,
): array

Product of array elements.

Computes the product of elements in an array or matrix. Optionally, computes the product along a specified dimension.

Examples

Product of a vector

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

assertEquals(prod([5, 6, 3]), 90);

Product of matrix elements along rows

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

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

Product of matrix elements along columns

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

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

Parameters

The input array or matrix of values

dim: 0

The dimension to operate along, 1 for columns, 0 for rows (default is 1)

Return Type

The product of the array elements, or an array of products if a matrix is provided

Throws

If no input arguments are provided

prod(
x: matrix,
dim: 1,
): array

Product of array elements.

Computes the product of elements in an array or matrix. Optionally, computes the product along a specified dimension.

Examples

Product of a vector

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

assertEquals(prod([5, 6, 3]), 90);

Product of matrix elements along rows

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

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

Product of matrix elements along columns

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

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

Parameters

The input array or matrix of values

dim: 1

The dimension to operate along, 1 for columns, 0 for rows (default is 1)

Return Type

The product of the array elements, or an array of products if a matrix is provided

Throws

If no input arguments are provided