function subset
subset(m: array): array

Extract a subset of an array or matrix based on row and column indices.

Extracts a subset from an array or matrix based on specified row and column indices. If the indices are not provided, the entire array or matrix is returned. Use ':' to select all rows or columns.

Examples

Extract a single element from an array

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

const c = [5, 6, 3];
assertEquals(subset(c, 1), 6);

Extract multiple elements from an array

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

const c = [5, 6, 3];

assertEquals(subset(c, [1, 2]), [6, 3]);

Extract the last element from an array

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

const c = [5, 6, 3];

assertEquals(subset(c, c.length - 1), 3);

Extract a single element from a matrix

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

const a = [[5, 6, 5], [7, 8, -1]];
assertEquals(subset(a, 0, 1), [[6]]);

Extract a submatrix

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

const a = [[5, 6, 5], [7, 8, -1]];

assertEquals(subset(a, [0, 1], [1, 2]), [[6, 5], [8, -1]]);

Extract an entire row

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

const a = [[5, 6, 5], [7, 8, -1]];

assertEquals(subset(a, 0, ':'), [[5, 6, 5]]);

Extract an entire column

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

const a = [[5, 6, 5], [7, 8, -1]];

assertEquals(subset(a, ':', 0), [[5], [7]]);

Parameters

The input array or matrix.

Return Type

The extracted subset of the array or matrix.

Throws

If the input arguments are invalid.

subset(m: matrix): matrix

Extract a subset of an array or matrix based on row and column indices.

Extracts a subset from an array or matrix based on specified row and column indices. If the indices are not provided, the entire array or matrix is returned. Use ':' to select all rows or columns.

Examples

Extract a single element from an array

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

const c = [5, 6, 3];
assertEquals(subset(c, 1), 6);

Extract multiple elements from an array

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

const c = [5, 6, 3];

assertEquals(subset(c, [1, 2]), [6, 3]);

Extract the last element from an array

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

const c = [5, 6, 3];

assertEquals(subset(c, c.length - 1), 3);

Extract a single element from a matrix

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

const a = [[5, 6, 5], [7, 8, -1]];
assertEquals(subset(a, 0, 1), [[6]]);

Extract a submatrix

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

const a = [[5, 6, 5], [7, 8, -1]];

assertEquals(subset(a, [0, 1], [1, 2]), [[6, 5], [8, -1]]);

Extract an entire row

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

const a = [[5, 6, 5], [7, 8, -1]];

assertEquals(subset(a, 0, ':'), [[5, 6, 5]]);

Extract an entire column

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

const a = [[5, 6, 5], [7, 8, -1]];

assertEquals(subset(a, ':', 0), [[5], [7]]);

Parameters

The input array or matrix.

Return Type

The extracted subset of the array or matrix.

Throws

If the input arguments are invalid.

subset(
m: array,
r: number,
): number

Extract a subset of an array or matrix based on row and column indices.

Extracts a subset from an array or matrix based on specified row and column indices. If the indices are not provided, the entire array or matrix is returned. Use ':' to select all rows or columns.

Examples

Extract a single element from an array

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

const c = [5, 6, 3];
assertEquals(subset(c, 1), 6);

Extract multiple elements from an array

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

const c = [5, 6, 3];

assertEquals(subset(c, [1, 2]), [6, 3]);

Extract the last element from an array

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

const c = [5, 6, 3];

assertEquals(subset(c, c.length - 1), 3);

Extract a single element from a matrix

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

const a = [[5, 6, 5], [7, 8, -1]];
assertEquals(subset(a, 0, 1), [[6]]);

Extract a submatrix

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

const a = [[5, 6, 5], [7, 8, -1]];

assertEquals(subset(a, [0, 1], [1, 2]), [[6, 5], [8, -1]]);

Extract an entire row

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

const a = [[5, 6, 5], [7, 8, -1]];

assertEquals(subset(a, 0, ':'), [[5, 6, 5]]);

Extract an entire column

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

const a = [[5, 6, 5], [7, 8, -1]];

assertEquals(subset(a, ':', 0), [[5], [7]]);

Parameters

The input array or matrix.

r: number

The row index or ':' for all rows.

Return Type

number

The extracted subset of the array or matrix.

Throws

If the input arguments are invalid.

subset(
m: array,
r: array,
): array

Extract a subset of an array or matrix based on row and column indices.

Extracts a subset from an array or matrix based on specified row and column indices. If the indices are not provided, the entire array or matrix is returned. Use ':' to select all rows or columns.

Examples

Extract a single element from an array

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

const c = [5, 6, 3];
assertEquals(subset(c, 1), 6);

Extract multiple elements from an array

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

const c = [5, 6, 3];

assertEquals(subset(c, [1, 2]), [6, 3]);

Extract the last element from an array

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

const c = [5, 6, 3];

assertEquals(subset(c, c.length - 1), 3);

Extract a single element from a matrix

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

const a = [[5, 6, 5], [7, 8, -1]];
assertEquals(subset(a, 0, 1), [[6]]);

Extract a submatrix

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

const a = [[5, 6, 5], [7, 8, -1]];

assertEquals(subset(a, [0, 1], [1, 2]), [[6, 5], [8, -1]]);

Extract an entire row

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

const a = [[5, 6, 5], [7, 8, -1]];

assertEquals(subset(a, 0, ':'), [[5, 6, 5]]);

Extract an entire column

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

const a = [[5, 6, 5], [7, 8, -1]];

assertEquals(subset(a, ':', 0), [[5], [7]]);

Parameters

The input array or matrix.

The row index or ':' for all rows.

Return Type

The extracted subset of the array or matrix.

Throws

If the input arguments are invalid.

subset(
m: matrix,
r:
number
| array
| string
,
c:
number
| array
| string
,
): array | matrix

Extract a subset of an array or matrix based on row and column indices.

Extracts a subset from an array or matrix based on specified row and column indices. If the indices are not provided, the entire array or matrix is returned. Use ':' to select all rows or columns.

Examples

Extract a single element from an array

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

const c = [5, 6, 3];
assertEquals(subset(c, 1), 6);

Extract multiple elements from an array

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

const c = [5, 6, 3];

assertEquals(subset(c, [1, 2]), [6, 3]);

Extract the last element from an array

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

const c = [5, 6, 3];

assertEquals(subset(c, c.length - 1), 3);

Extract a single element from a matrix

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

const a = [[5, 6, 5], [7, 8, -1]];
assertEquals(subset(a, 0, 1), [[6]]);

Extract a submatrix

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

const a = [[5, 6, 5], [7, 8, -1]];

assertEquals(subset(a, [0, 1], [1, 2]), [[6, 5], [8, -1]]);

Extract an entire row

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

const a = [[5, 6, 5], [7, 8, -1]];

assertEquals(subset(a, 0, ':'), [[5, 6, 5]]);

Extract an entire column

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

const a = [[5, 6, 5], [7, 8, -1]];

assertEquals(subset(a, ':', 0), [[5], [7]]);

Parameters

The input array or matrix.

r:
number
| array
| string

The row index or ':' for all rows.

c:
number
| array
| string

The column index or ':' for all columns.

Return Type

The extracted subset of the array or matrix.

Throws

If the input arguments are invalid.

subset(
r?:
number
| array
| string
,
c?:
number
| array
| string
,
):
number
| array
| matrix

Extract a subset of an array or matrix based on row and column indices.

Extracts a subset from an array or matrix based on specified row and column indices. If the indices are not provided, the entire array or matrix is returned. Use ':' to select all rows or columns.

Examples

Extract a single element from an array

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

const c = [5, 6, 3];
assertEquals(subset(c, 1), 6);

Extract multiple elements from an array

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

const c = [5, 6, 3];

assertEquals(subset(c, [1, 2]), [6, 3]);

Extract the last element from an array

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

const c = [5, 6, 3];

assertEquals(subset(c, c.length - 1), 3);

Extract a single element from a matrix

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

const a = [[5, 6, 5], [7, 8, -1]];
assertEquals(subset(a, 0, 1), [[6]]);

Extract a submatrix

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

const a = [[5, 6, 5], [7, 8, -1]];

assertEquals(subset(a, [0, 1], [1, 2]), [[6, 5], [8, -1]]);

Extract an entire row

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

const a = [[5, 6, 5], [7, 8, -1]];

assertEquals(subset(a, 0, ':'), [[5, 6, 5]]);

Extract an entire column

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

const a = [[5, 6, 5], [7, 8, -1]];

assertEquals(subset(a, ':', 0), [[5], [7]]);

Parameters

The input array or matrix.

optional
r:
number
| array
| string

The row index or ':' for all rows.

optional
c:
number
| array
| string

The column index or ':' for all columns.

Return Type

number
| array
| matrix

The extracted subset of the array or matrix.

Throws

If the input arguments are invalid.

Usage

import subset from "matarrs/subset.ts";