Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

atleast3d

Convert a list of values (scalars and/or ndarrays) to ndarrays having at least three dimensions.

Usage

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

atleast3d( arrays )

Converts a list of values (scalars and/or ndarrays) to ndarrays having at least three dimensions.

var array = require( '@stdlib/ndarray/array' );
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );

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

var y = scalar2ndarray( 3.14 );
// returns <ndarray>[ 3.14 ]

var out = atleast3d( [ x, y ] );
// returns [ <ndarray>, <ndarray> ]

The function accepts the following arguments:

  • arrays: array-like object containing a list of scalars and/or ndarrays.

Notes

  • If a provided ndarray has fewer than three dimensions, the function prepends singleton dimensions, and the returned ndarray is a view on the input ndarray data buffer.

  • The returned ndarray is a "base" ndarray, and, thus, the returned ndarray does not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast an ndarray-like object within internal implementations and to do so with minimal overhead.

  • If provided a scalar value (i.e., a non-ndarray) and that value

    • is a number, the returned ndarray will have the default real-valued floating-point data type.
    • is a boolean, the returned ndarray will have the default boolean data type.
    • is a complex number object of a known data type, the data type of the returned ndarray will be the same as the provided value.
    • is a complex number object of an unknown data type, the returned ndarray will have the default complex-valued floating-point data type.
    • is any other value type, the returned ndarray will have a 'generic' data type.

Examples

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

var x = discreteUniform( [ 2, 2, 2 ], -100, 100 );
console.log( ndarray2array( x ) );

var y = scalar2ndarray( 3.14 );
console.log( ndarray2array( y ) );

var out = atleast3d( [ x, y ] );
console.log( ndarray2array( out[ 0 ] ) );
console.log( ndarray2array( out[ 1 ] ) );