Skip to content

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

@fangq

Description

@fangq

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions