Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

empty

Create an uninitialized ndarray having a specified shape and data type.

Usage

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

empty( dtype, shape, order )

Creates an uninitialized ndarray having a specified shape and data type.

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

var arr = empty( 'float64', [ 2, 2 ], 'row-major' );
// returns <ndarray>

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

var dt = String( getDType( arr ) );
// returns 'float64'

The function accepts the following arguments:

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

Notes

  • If dtype is 'generic', the function always returns a zero-filled array.
  • For returned ndarrays whose underlying memory is not initialized, memory contents are unknown and may contain sensitive data.

Examples

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

// Get a list of data types:
var dt = dtypes( 'integer_and_generic' );

// Generate uninitialized arrays...
var arr;
var i;
for ( i = 0; i < dt.length; i++ ) {
    arr = empty( dt[ i ], [ 2, 2 ], 'row-major' );
    console.log( ndarray2array( arr ) );
}