Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

full

Create an ndarray filled with a specified value and having a specified shape and data type.

Usage

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

full( value, dtype, shape, order )

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:

  • value: scalar fill value.
  • dtype: underlying data type.
  • shape: array shape.
  • order: specifies whether an ndarray is 'row-major' (C-style) or 'column-major' (Fortran-style).

Notes

  • If value is a number and dtype is a complex data type, the function casts the number to 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 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).

Examples

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 ) );
}