function histc
histc(
x: array,
bins?: number | array,
dim?: 0 | 1,
): HistBin[]

Histogram count.

Counts the number of values in x that fall between the elements in the bins array. Values outside the range in bins are not counted. Returns an array of objects with bin edges, counts, and frequencies.

Examples

Simple histogram with default bins

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

assertEquals(histc([1, 2, 3, 4, 5], 5).length, 6);

Histogram with custom bin edges

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

assertEquals(histc([1, 5, 10], [0, 5, 10]).length, 3);

Matrix histogram

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

assertEquals(histc([[1, 2], [3, 4]], 2).length, 2);

Parameters

Input array or matrix

optional
bins: number | array

Number of bins or array of bin edges. Default is 10

optional
dim: 0 | 1

Dimension along which to compute histogram. Default is 0

Return Type

Array of objects with bins, count, and freq properties

Throws

When input is invalid

histc(
x: matrix,
bins?: number | array,
dim?: 0 | 1,
): HistBin[][]

Histogram count.

Counts the number of values in x that fall between the elements in the bins array. Values outside the range in bins are not counted. Returns an array of objects with bin edges, counts, and frequencies.

Examples

Simple histogram with default bins

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

assertEquals(histc([1, 2, 3, 4, 5], 5).length, 6);

Histogram with custom bin edges

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

assertEquals(histc([1, 5, 10], [0, 5, 10]).length, 3);

Matrix histogram

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

assertEquals(histc([[1, 2], [3, 4]], 2).length, 2);

Parameters

Input array or matrix

optional
bins: number | array

Number of bins or array of bin edges. Default is 10

optional
dim: 0 | 1

Dimension along which to compute histogram. Default is 0

Return Type

Array of objects with bins, count, and freq properties

Throws

When input is invalid