Skip to content

stdlib-js/blas-ext-zero-to

About stdlib...

We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.

The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.

When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.

To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!

zeroTo

NPM version Build Status Coverage Status

Return a new ndarray filled with linearly spaced numeric elements which increment by 1 starting from zero along one or more ndarray dimensions.

Installation

npm install @stdlib/blas-ext-zero-to

Alternatively,

  • To load the package in a website via a script tag without installation and bundlers, use the ES Module available on the esm branch (see README).
  • If you are using Deno, visit the deno branch (see README for usage intructions).
  • For use in Observable, or in browser/node environments, use the Universal Module Definition (UMD) build available on the umd branch (see README).

The branches.md file summarizes the available branches and displays a diagram illustrating their relationships.

To view installation and usage instructions specific to each branch build, be sure to explicitly navigate to the respective README files on each branch, as linked to above.

Usage

var zeroTo = require( '@stdlib/blas-ext-zero-to' );

zeroTo( shape[, options] )

Returns a new ndarray filled with linearly spaced numeric elements which increment by 1 starting from zero along one or more ndarray dimensions.

var x = zeroTo( [ 2, 3 ] );
// returns <ndarray>[ [ 0.0, 1.0, 2.0 ], [ 0.0, 1.0, 2.0 ] ]

The function has the following parameters:

  • shape: array shape.
  • options: function options (optional).

The function accepts the following options:

  • dims: list of dimensions over which to perform operation. If not provided, the function generates values along the last dimension. Default: [-1].
  • dtype: output ndarray data type. Must be a numeric or "generic" data type. Default: 'float64'.
  • order: specifies whether an ndarray is 'row-major' (C-style) or 'column-major' (Fortran-style). Default: 'row-major'.
  • mode: specifies how to handle indices which exceed array dimensions (see ndarray). Default: 'throw'.
  • submode: a mode array which specifies for each dimension how to handle subscripts which exceed array dimensions (see ndarray). If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. Default: [ options.mode ].

By default, the function generates values along the last dimension of an output ndarray. To perform the operation over specific dimensions, provide a dims option.

var x = zeroTo( [ 2, 2 ], {
    'dims': [ 0, 1 ]
});
// returns <ndarray>[ [ 0.0, 1.0 ], [ 2.0, 3.0 ] ]

To specify the output ndarray data type, provide a dtype option.

var x = zeroTo( [ 3 ], {
    'dtype': 'float32'
});
// returns <ndarray>[ 0.0, 1.0, 2.0 ]

zeroTo.assign( x[, options] )

Fills an ndarray with linearly spaced numeric elements which increment by 1 starting from zero along one or more ndarray dimensions.

var zeros = require( '@stdlib/ndarray-zeros' );

var x = zeros( [ 2, 3 ] );
// returns <ndarray>[ [ 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0 ] ]

var out = zeroTo.assign( x );
// returns <ndarray>[ [ 0.0, 1.0, 2.0 ], [ 0.0, 1.0, 2.0 ] ]

var bool = ( x === out );
// returns true

The function has the following parameters:

  • x: input ndarray. Must have a numeric or "generic" data type.
  • options: function options (optional).

The function accepts the following options:

  • dims: list of dimensions over which to perform operation. If not provided, the function generates values along the last dimension. Default: [-1].

Notes

  • The function iterates over ndarray elements according to the memory layout of the input ndarray. Accordingly, performance degradation is possible when operating over multiple dimensions of a large non-contiguous multi-dimensional input ndarray. In such scenarios, one may want to copy an input ndarray to contiguous memory before performing the operation.

Examples

var ndarray2array = require( '@stdlib/ndarray-to-array' );
var zeroTo = require( '@stdlib/blas-ext-zero-to' );

// Create a new ndarray:
var x = zeroTo( [ 5, 5 ], {
    'dtype': 'generic'
});
console.log( ndarray2array( x ) );

// Generate values over a specific dimension:
x = zeroTo( [ 5, 5 ], {
    'dtype': 'generic',
    'dims': [ 0 ]
});
console.log( ndarray2array( x ) );

// Generate values over all dimensions:
x = zeroTo( [ 5, 5 ], {
    'dtype': 'generic',
    'dims': [ 0, 1 ]
});
console.log( ndarray2array( x ) );

Notice

This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.

For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.

Community

Chat


License

See LICENSE.

Copyright

Copyright © 2016-2026. The Stdlib Authors.

About

Return a new ndarray filled with linearly spaced numeric elements which increment by 1 starting from zero along one or more ndarray dimensions.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors