Create an ndarray filled with
falsevalues and having the same shape and data type as a provided ndarray.
var falsesLike = require( '@stdlib/ndarray/falses-like' );Creates an ndarray filled with false values and having the same shape and data type as a provided ndarray.
var getShape = require( '@stdlib/ndarray/shape' );
var getDType = require( '@stdlib/ndarray/dtype' );
var empty = require( '@stdlib/ndarray/empty' );
var x = empty( [ 2, 2 ], {
'dtype': 'bool'
});
// returns <ndarray>
var y = falsesLike( x );
// returns <ndarray>[ [ false, false ], [ false, false ] ]
var sh = getShape( y );
// returns [ 2, 2 ]
var dt = String( getDType( y ) );
// returns 'bool'The function supports the following options:
- dtype: output ndarray data type. Must be a boolean or "generic" data type. Overrides the input ndarray's inferred data type.
- shape: output ndarray shape. Overrides the input ndarray's inferred shape.
- order: specifies whether the output ndarray should be
'row-major'(C-style) or'column-major'(Fortran-style). Overrides the input ndarray's inferred order. - mode: specifies how to handle indices which exceed array dimensions (see ndarray). Default:
'throw'. - submode: a mode array which specifies for each dimension how to handle subscripts which exceed array dimensions (see ndarray). If provided fewer modes than dimensions, the constructor recycles modes using modulo arithmetic. Default:
[ options.mode ]. - readonly: boolean indicating whether an array should be read-only. Default:
false.
To override either the dtype, shape, or order, specify the corresponding option. For example, to override the inferred data type,
var getShape = require( '@stdlib/ndarray/shape' );
var getDType = require( '@stdlib/ndarray/dtype' );
var empty = require( '@stdlib/ndarray/empty' );
var x = empty( [ 2, 2 ], {
'dtype': 'bool'
});
// returns <ndarray>
var dt = String( getDType( x ) );
// returns 'bool'
var y = falsesLike( x, {
'dtype': 'generic'
});
// returns <ndarray>[ [ false, false ], [ false, false ] ]
var sh = getShape( y );
// returns [ 2, 2 ]
dt = String( getDType( y ) );
// returns 'generic'var empty = require( '@stdlib/ndarray/empty' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var falsesLike = require( '@stdlib/ndarray/falses-like' );
// Specify a list of data types:
var dt = [
'bool',
'generic'
];
// Generate filled ndarrays...
var x;
var y;
var i;
for ( i = 0; i < dt.length; i++ ) {
x = empty( [ 2, 2 ], {
'dtype': dt[ i ]
});
y = falsesLike( x );
console.log( ndarray2array( y ) );
}