numjs icon indicating copy to clipboard operation
numjs copied to clipboard

can one access the TypedArray buffer after `.pick` or `.slice`?

Open fangq opened this issue 5 months ago • 0 comments

this is not a bug, but a question

I am wondering if it is possible to access the underlying TypedArray buffer after .pick or .slice? I noticed that calling .selection.data always returns the full array, not the selected subset.

one need arises from sorting each row of a 2-D matrix. I can achieve this by first calling .tolist() and then call Array.sort

var c = nj.array([[2, 3, 4, 10],[5,6,7,9],[8, 3, 1, 12]]).T;
for(let i=0; i<6; i++) {
  console.log(c.pick(i).tolist().sort((a,b) => a-b));
}

although I would like to do the sorting directly on the TypedArray buffer. is this possible?

also, what is the best way to copy one row/column from one matrix to another? I tried matrix1.pick(i).assign(matrix2.pick(j)), however, it does not seems to actually copy the value.

fangq avatar Feb 03 '24 22:02 fangq