Skip to content

Any standard way to unindex ? #30

Description

@peoro

I need a function that, given an index in the underlying array, returns the ndarray index: [i,j,...];

I implemented it in my code (without the compilation logic of ndarray), and thought it might be useful within this project, since index is already there.

function unindex(ndarr, n)
{
    const result = new Array( ndarr.shape.length );

    n = n - ndarr.offset;
    ndarr.stride.forEach( (stride, i)=>{
        result[i] = Math.floor( n / stride );
        n %= stride;
    });

    return result;
};

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions