Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

fill

Fill an input ndarray with a specified value.

Usage

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

fill( x, value )

Fills an input ndarray with a specified value.

var array = require( '@stdlib/ndarray/array' );

var x = array( [ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ], [ [ 5.0, 6.0 ] ] ] );
// returns <ndarray>[ [ [ 1.0, 2.0 ] ], [ [ 3.0, 4.0 ] ], [ [ 5.0, 6.0 ] ] ]

var out = fill( x, 10.0 );
// returns <ndarray>[ [ [ 10.0, 10.0 ] ], [ [ 10.0, 10.0 ] ], [ [ 10.0, 10.0 ] ] ]

var bool = ( out === x );
// returns true

The function accepts the following arguments:

  • x: input ndarray.
  • value: scalar value.

Notes

  • A provided ndarray should be an object with the following properties:

    • dtype: data type.
    • data: data buffer.
    • shape: dimensions.
    • strides: stride lengths.
    • offset: index offset.
    • order: specifies whether an ndarray is row-major (C-style) or column major (Fortran-style).
  • If value is a number and x has a complex data type, the function fills an input ndarray with a complex number whose real component equals the provided scalar value and whose imaginary component is zero.

  • A value must be able to safely cast to the input 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' input ndarray).

  • The function mutates the input ndarray.

Examples

var discreteUniform = require( '@stdlib/random/discrete-uniform' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var fill = require( '@stdlib/ndarray/base/fill' );

var x = discreteUniform( [ 5, 2 ], -100, 100, {
    'dtype': 'generic'
});
console.log( ndarray2array( x ) );

fill( x, 10.0 );
console.log( ndarray2array( x ) );