Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

nullsLike

Create a null-filled ndarray having the same shape and data type as a provided ndarray.

Usage

var nullsLike = require( '@stdlib/ndarray/base/nulls-like' );

nullsLike( x )

Creates a null-filled ndarray having the same shape and data type as a provided ndarray.

var getShape = require( '@stdlib/ndarray/shape' );
var empty = require( '@stdlib/ndarray/empty' );

var x = empty( [ 2, 2 ], {
    'dtype': 'generic'
});
// returns <ndarray>

var y = nullsLike( x );
// returns <ndarray>[ [ null, null ], [ null, null ] ]

var sh = getShape( y );
// returns [ 2, 2 ]

Notes

  • Along with data type, shape, and order, the function infers the "class" of the returned ndarray from the provided ndarray. For example, if provided a "base" ndarray, the function returns a base ndarray. If provided a non-base ndarray, the function returns a non-base ndarray.

Examples

var empty = require( '@stdlib/ndarray/empty' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var nullsLike = require( '@stdlib/ndarray/base/nulls-like' );

// Specify a list of data types:
var dt = [
    'generic'
];

// Generate null-filled arrays...
var x;
var y;
var i;
for ( i = 0; i < dt.length; i++ ) {
    x = empty( [ 2, 2 ], {
        'dtype': dt[ i ]
    });
    y = nullsLike( x );
    console.log( ndarray2array( y ) );
}