@stdlib/ndarray-base-ndarraylike2scalar
v0.1.1
Published
Convert an ndarray-like object to a scalar value.
Readme
ndarraylike2scalar
Convert an ndarray-like object to a scalar value.
Installation
npm install @stdlib/ndarray-base-ndarraylike2scalarUsage
var ndarraylike2scalar = require( '@stdlib/ndarray-base-ndarraylike2scalar' );ndarraylike2scalar( x )
Converts an ndarray-like object to a scalar value.
var scalar2ndarray = require( '@stdlib/ndarray-from-scalar' );
var arr = scalar2ndarray( 1.0 );
// returns <ndarray>
var out = ndarraylike2scalar( arr );
// returns 1.0Examples
var scalar2ndarray = require( '@stdlib/ndarray-from-scalar' );
var compose = require( '@stdlib/utils-compose' );
var naryFunction = require( '@stdlib/utils-nary-function' );
var oneTo = require( '@stdlib/array-one-to' );
var logEachMap = require( '@stdlib/console-log-each-map' );
var ndarraylike2scalar = require( '@stdlib/ndarray-base-ndarraylike2scalar' );
// Create a list of scalars:
var scalars = oneTo( 10 );
// Create a composite function which round-trips a scalar to an ndarray and back:
var f = compose( ndarraylike2scalar, naryFunction( scalar2ndarray, 1 ) );
// Apply the function to the list of scalars:
logEachMap( '%d => %d', scalars, f );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
License
See LICENSE.
Copyright
Copyright © 2016-2026. The Stdlib Authors.
