Skip to content

Latest commit

 

History

History
132 lines (79 loc) · 3.2 KB

File metadata and controls

132 lines (79 loc) · 3.2 KB

ndarray2string

Serialize an ndarray as a string.

Usage

var ndarray2string = require( '@stdlib/ndarray/to-string' );

ndarray2string( x )

Serializes an ndarray as a string.

var array = require( '@stdlib/ndarray/array' );

var x = array( [ 1, 2, 3, 4 ], {
    'shape': [ 2, 2 ]
});
// returns <ndarray>

var str = ndarray2string( x );
// returns "ndarray( 'float64', new Float64Array( [ 1, 2, 3, 4 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' )"

Notes

  • The function does not serialize data outside of the buffer defined by the ndarray view.
  • For ndarrays with more than 100 elements, the function abbreviates the data, showing only the first and last three values.

Examples

var array = require( '@stdlib/ndarray/array' );
var ndarray2string = require( '@stdlib/ndarray/to-string' );

// Create a 2x3 ndarray:
var x = array( [ 1, 2, 3, 4, 5, 6 ], {
    'shape': [ 2, 3 ],
    'dtype': 'generic'
});

// Serialize the ndarray as a string:
var str = ndarray2string( x );
console.log( str );
// => 'ndarray( \'generic\', [ 1, 2, 3, 4, 5, 6 ], [ 2, 3 ], [ 3, 1 ], 0, \'row-major\' )'