Copy an input ndarray to a new ndarray having the same shape and data type.
var copy = require( '@stdlib/ndarray/base/copy' );Copies an input ndarray to a new ndarray having the same shape and data type.
var getShape = require( '@stdlib/ndarray/shape' );
var zeros = require( '@stdlib/ndarray/base/zeros' );
var x = zeros( 'float64', [ 2, 2 ], 'row-major' );
// returns <ndarray>
var y = copy( x );
// returns <ndarray>
var sh = getShape( y );
// returns [ 2, 2 ]- The function performs a full copy in which an ndarray's underlying data is copied to a new underlying data buffer.
- 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.
var bernoulli = require( '@stdlib/random/array/bernoulli' );
var array = require( '@stdlib/ndarray/array' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var copy = require( '@stdlib/ndarray/base/copy' );
var xbuf = bernoulli( 10, 0.9, {
'dtype': 'generic'
});
var x = array({
'dtype': 'generic',
'data': xbuf,
'shape': [ 5, 2 ],
'strides': [ 2, 1 ],
'offset': 0,
'order': 'row-major'
});
console.log( ndarray2array( x ) );
var o = copy( x );
console.log( ndarray2array( o ) );