0.2.1 • Published 2 months ago

@stdlib/array-shape v0.2.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 months ago

Array Shape

NPM version Build Status Coverage Status

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


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

Chat


License

See LICENSE.

Copyright

Copyright © 2016-2024. The Stdlib Authors.