Skip to content

ndarray not getting value as expected. #37

Description

@softmarshmallow

im trying to create a list with some specific rules.
ex ) x :2, y:5
0, 0
0, 1
0, 2
0, 3
0, 4
1, 0
1, 1
1, 2
1, 3
1, 4

it should have 2 sets, y should be repeated for x times.
so the table shape should be [2, x * y].
1D data should look like [0, 1, 0, 2, 0, 3, 0, 4, 1, 0, 1, 1, 1, 2, 1, 3, 1, 4]

it works fine until here but when i try to get myNdarray.get(0, 5), i expected 1 but gives 2 instead.

    let x = 2;
    let y = 4;

    let datArr = []
    for (let xx = 0; xx < x; xx++){
        for (let yy = 0; yy < y; yy++){
            datArr.push(xx)
            datArr.push(yy)
            // narr.
        }
    }
    let narr = ndarray(new Float32Array(datArr), [2, x*y]);
    console.log(narr)
    console.log(narr.get(0, 5))
    console.log(narr.get(1, 5))

here is my test code, and

this is the log

NdArrayTest.js:35 View2dfloat32 {data: Float32Array(20), shape: Array(2), stride: Array(2), offset: 0}data: Float32Array(20) [0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 1, 0, 1, 1, 1, 2, 1, 3, 1, 4]offset: 0shape: (2) [2, 10]stride: (2) [10, 1]order: (...)size: (...)proto: Object
NdArrayTest.js:36 2
NdArrayTest.js:37 2

what is happening?
am i using the wrong code?

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