function nrows
nrows(x: array | matrix): number

Returns the number of rows in an array or matrix.

Returns the number of rows in a 1D array (treated as a row vector) or a 2D matrix.

Examples

Row vector (1D array)

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

assertEquals(nrows([5, 6, 7]), 1);

Matrix with multiple rows (2D array)

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

assertEquals(nrows([[3, 2, 7], [4, 5, 6]]), 2);

Parameters

Array or matrix of elements.

Return Type

number

The number of rows in the input.

Throws

Throws an error if no input is provided or if the input is not an array.

Usage

import nrows from "matarrs/nrows.ts";