You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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))
The first thing that jumps out is the possibility of mistakes when making assumptions about the 1D data buffer. Can you use .set() instead and examine narr.data to see what it looks like instead of passing the data buffer directly? It's very slightly slower, but for the majority cases is equivalent and at least much less error-prone.
Activity
rreusser commentedon Mar 28, 2018
The first thing that jumps out is the possibility of mistakes when making assumptions about the 1D data buffer. Can you use
.set()instead and examinenarr.datato see what it looks like instead of passing the data buffer directly? It's very slightly slower, but for the majority cases is equivalent and at least much less error-prone.wangzhuwei212003 commentedon Aug 7, 2018
First,if you want x = 2, y = 5, the value of y in you code should be 5 not 4.
If
is the normal array you want, then it is.
narr.get(0, 5)is 2, I dont know why you expect 1 ?narr.get(1, 5)is also 2.