time-to-botec/js/node_modules/@stdlib/array/shape/README.md
NunoSempere b6addc7f05 feat: add the node modules
Necessary in order to clearly see the squiggle hotwiring.
2022-12-03 12:44:49 +00:00

3.5 KiB

Array Shape

Determine (nested) array dimensions.

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 shape;
var arr;

arr = [ 1, 2, 3 ];
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 ]