Fill an input
ndarraywith a specified value.
var fill = require( '@stdlib/ndarray/fill' );Fills an input ndarray with a specified value.
var zeros = require( '@stdlib/ndarray/zeros' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var x = zeros( [ 3, 1, 2 ], {
'dtype': 'float64'
});
var y = fill( x, 10.0 );
// returns <ndarray>
var bool = ( y === x );
// returns true
var arr = ndarray2array( x );
// returns [ [ [ 10.0, 10.0 ] ], [ [ 10.0, 10.0 ] ], [ [ 10.0, 10.0 ] ] ]The function accepts the following arguments:
- x: array-like object containing an input
ndarray. - value: scalar value.
- An input
ndarraymust be writable. If provided a read-onlyndarray, the function throws an error. - If
valueis a number andxhas a complex data type, the function fills an inputndarraywith a complex number whose real component equals the provided scalarvalueand whose imaginary component is zero. - A
valuemust be able to safely cast to the inputndarraydata 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'inputndarray). - The function mutates the input
ndarray.
var zeros = require( '@stdlib/ndarray/zeros' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var fill = require( '@stdlib/ndarray/fill' );
// Create a zero-filled ndarray:
var x = zeros( [ 5, 2 ], {
'dtype': 'generic'
});
console.log( ndarray2array( x ) );
// Fill the ndarray with a scalar value:
fill( x, 10.0 );
console.log( ndarray2array( x ) );@stdlib/ndarray/fill-by: fill an input ndarray according to a callback function.@stdlib/ndarray/map: apply a callback to elements in an input ndarray and assign results to elements in a new output ndarray.@stdlib/ndarray/zeros: create a zero-filled ndarray having a specified shape and data type.