Skip to main content

arange

Return evenly spaced values within a given interval. When called with a single argument, it is treated as stop and start defaults to 0.
function arange(start: number, stop?: number, step?: number, dtype?: DType): NDArray
NameTypeDefaultDescription
startnumber0Start of the interval (inclusive). If stop is omitted, this value is used as stop and start becomes 0.
stopnumber-End of the interval (exclusive).
stepnumber1Spacing between values.
dtypeDType'float64'Data type of the output array.
Returns: NDArray — 1-D array of evenly spaced values.
import * as np from 'numpy-ts';

const a = np.arange(5);
// array([0, 1, 2, 3, 4])

const b = np.arange(2, 10, 2);
// array([2, 4, 6, 8])

const c = np.arange(0, 1, 0.25);
// array([0, 0.25, 0.5, 0.75])

linspace

Return evenly spaced numbers over a specified interval. Unlike arange, the stop value is included by default.
function linspace(
  start: number,
  stop: number,
  num?: number,
  dtype?: DType
): NDArray
NameTypeDefaultDescription
startnumber-Start value of the sequence.
stopnumber-End value of the sequence (inclusive).
numnumber50Number of samples to generate.
dtypeDType'float64'Data type of the output array.
Returns: NDArray — 1-D array of num evenly spaced values from start to stop.
import * as np from 'numpy-ts';

const a = np.linspace(0, 1, 5);
// array([0, 0.25, 0.5, 0.75, 1])

const b = np.linspace(0, 10, 3);
// array([0, 5, 10])

logspace

Return numbers spaced evenly on a log scale. In the default base 10, start and stop are exponents: the sequence runs from base**start to base**stop.
function logspace(
  start: number,
  stop: number,
  num?: number,
  base?: number,
  dtype?: DType
): NDArray
NameTypeDefaultDescription
startnumber-base**start is the starting value of the sequence.
stopnumber-base**stop is the final value of the sequence.
numnumber50Number of samples to generate.
basenumber10.0The base of the log space.
dtypeDType'float64'Data type of the output array.
Returns: NDArray — 1-D array of num samples, equally spaced on a log scale.
import * as np from 'numpy-ts';

const a = np.logspace(0, 2, 3);
// array([1, 10, 100])  -- 10^0, 10^1, 10^2

const b = np.logspace(0, 3, 4, 2);
// array([1, 2, 4, 8])  -- 2^0, 2^1, 2^2, 2^3

geomspace

Return numbers spaced evenly on a log scale (a geometric sequence). Unlike logspace, start and stop are the actual start/stop values, not exponents.
function geomspace(
  start: number,
  stop: number,
  num?: number,
  dtype?: DType
): NDArray
NameTypeDefaultDescription
startnumber-The starting value of the sequence. Must be non-zero.
stopnumber-The final value of the sequence. Must be non-zero and same sign as start.
numnumber50Number of samples to generate.
dtypeDType'float64'Data type of the output array.
Returns: NDArray — 1-D array of num samples, equally spaced on a geometric (log) scale. Throws: Error if start or stop is zero, or if they have different signs.
import * as np from 'numpy-ts';

const a = np.geomspace(1, 1000, 4);
// array([1, 10, 100, 1000])

const b = np.geomspace(1, 256, 9);
// array([1, 2, 4, 8, 16, 32, 64, 128, 256])