Create an ndarray filled with a specified value and having a specified shape and data type.
var full = require( '@stdlib/ndarray/base/full' );Returns an ndarray filled with a specified value and having a specified shape and data type.
var getShape = require( '@stdlib/ndarray/shape' );
var getDType = require( '@stdlib/ndarray/dtype' );
var arr = full( 10.0, 'float64', [ 2, 2 ], 'row-major' );
// returns <ndarray>[ [ 10.0, 10.0 ], [ 10.0, 10.0 ] ]
var sh = getShape( arr );
// returns [ 2, 2 ]
var dt = String( getDType( arr ) );
// returns 'float64'This function accepts the following arguments:
- If
valueis a number anddtypeis a complex data type, the function casts the number to a complex number whose real component equals the provided scalarvalueand whose imaginary component is zero. - A
valuemust be able to safely cast to the output ndarray data type. Scalar values having floating-point data types (both real and complex) are allowed to downcast to a lower precision data type of the same kind (e.g., a scalar double-precision floating-point number can be used to fill a'float32'output ndarray).
var dtypes = require( '@stdlib/ndarray/dtypes' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var full = require( '@stdlib/ndarray/base/full' );
// Get a list of data types:
var dt = dtypes( 'integer_and_generic' );
// Generate initialized arrays...
var arr;
var i;
for ( i = 0; i < dt.length; i++ ) {
arr = full( 10, dt[ i ], [ 2, 2 ], 'row-major' );
console.log( ndarray2array( arr ) );
}