Negligent Parachute Maintainers

    @stdlib/array-shape
    TypeScript icon, indicating that this package has built-in type declarations

    0.0.4 • Public • Published

    Array Shape

    NPM version Build Status Coverage Status dependencies

    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 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 ]

    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-2021. The Stdlib Authors.

    Install

    npm i @stdlib/array-shape

    Homepage

    stdlib.io

    DownloadsWeekly Downloads

    45

    Version

    0.0.4

    License

    Apache-2.0

    Unpacked Size

    38.7 kB

    Total Files

    10

    Last publish

    Collaborators

    • avatar
    • avatar
    • avatar
    • avatar