scalar2ndarray
Convert a scalar value to a zero-dimensional ndarray.
Usage
var scalar2ndarray = require( '@stdlib/ndarray/base/from-scalar' );
scalar2ndarray( value, dtype, order )
Returns a zero-dimensional ndarray
containing a provided scalar value
and having a specified data type.
var x = scalar2ndarray( 1.0, 'float64', 'row-major' );
// returns <ndarray>
var sh = x.shape;
// returns []
var dt = x.dtype;
// returns 'float64'
var v = x.get();
// returns 1.0
Notes
Examples
var dtypes = require( '@stdlib/ndarray/dtypes' );
var scalar2ndarray = require( '@stdlib/ndarray/base/from-scalar' );
// Get a list of data types:
var dt = dtypes();
// Generate zero-dimensional arrays...
var x;
var i;
for ( i = 0; i < dt.length; i++ ) {
x = scalar2ndarray( i, dt[ i ], 'row-major' );
console.log( x.get() );
}