@stdlib/ndarray-base-numel

Return the number of elements in an array.

Usage no npm install needed!

<script type="module">
  import stdlibNdarrayBaseNumel from 'https://cdn.skypack.dev/@stdlib/ndarray-base-numel';
</script>

README

numel

NPM version Build Status Coverage Status

Return the number of elements in an array.

Installation

npm install @stdlib/ndarray-base-numel

Usage

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

numel( shape )

Returns number of elements in an array.

var n = numel( [ 3, 2, 3 ] );
// returns 18

Examples

var discreteUniform = require( '@stdlib/random-base-discrete-uniform' );
var numel = require( '@stdlib/ndarray-base-numel' );

var shape;
var n;
var i;

shape = [ 0, 0, 0 ];
for ( i = 0; i < 100; i++ ) {
    // Generate random NxMxL dimensions:
    shape[ 0 ] = discreteUniform( 1, 10 );
    shape[ 1 ] = discreteUniform( 2, 7 );
    shape[ 2 ] = discreteUniform( 1, 12 );

    n = numel( shape );
    console.log( '%s => %d elements', shape.join( 'x' ), n );
}

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-2022. The Stdlib Authors.