@stdlib/array-shape
v0.2.2
Published
Determine (nested) array dimensions.
Downloads
7,353
Readme
Array Shape
Determine (nested) array dimensions.
Installation
npm install @stdlib/array-shape
Usage
var arrayShape = require( '@stdlib/array-shape' );
arrayShape( arr )
Returns array dimensions.
var arr = [
[ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8, 9 ]
];
var shape = arrayShape( arr );
// returns [ 3, 3 ]
The function ignores inconsistent dimensions.
var arr = [
[ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8 ]
];
var shape = arrayShape( arr );
// returns [ 3 ]
Examples
var arrayShape = require( '@stdlib/array-shape' );
var arr = [ 1, 2, 3 ];
var shape = arrayShape( arr );
// returns [ 3 ]
arr = [
[ 1 ],
[ 2 ],
[ 3 ]
];
shape = arrayShape( arr );
// returns [ 3, 1 ]
arr = [
[],
[],
[]
];
shape = arrayShape( arr );
// returns [ 3, 0 ]
arr = [
[ 1, 2, 3 ]
];
shape = arrayShape( arr );
// returns [ 1, 3 ]
arr = [
[ [ 1 ] ],
[ [ 2 ] ],
[ [ 3 ] ]
];
shape = arrayShape( arr );
// returns [ 3, 1, 1 ]
arr = [ [ [ [ 1, 2, 3 ] ] ] ];
shape = arrayShape( arr );
// returns [ 1, 1, 1, 3 ]
arr = [
[ 1, 2 ],
[ 3, 4 ]
];
shape = arrayShape( arr );
// returns [ 2, 2 ]
arr = [
[ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8, 9 ]
];
shape = arrayShape( arr );
// returns [ 3, 3 ]
arr = [
[ 1, 2, 3 ],
null,
[ 7, 8, 9 ]
];
shape = arrayShape( arr );
// returns [ 3 ]
arr = [
[ 1, 2, 3 ],
[ [ 4, 5, 6 ] ],
[ [ 7, 8, 9 ] ]
];
shape = arrayShape( arr );
// returns [ 3 ]
arr = [
[ [ 1, 2, 3 ] ],
[ 4, 5, 6 ],
[ [ 7, 8, 9 ] ]
];
shape = arrayShape( arr );
// returns [ 3 ]
arr = [
[ [ 1, 2, 3 ] ],
[ [ 4, 5, 6 ] ],
[ 7, 8, 9 ]
];
shape = arrayShape( arr );
// returns [ 3 ]
arr = [
[ [ [ 1, 2, 3 ] ] ],
[ [ 4, 5, 6 ] ],
[ [ [ 7, 8, 9 ] ] ]
];
shape = arrayShape( arr );
// returns [ 3, 1 ]
See Also
@stdlib/ndarray-ctor
: multidimensional array constructor.
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.