Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

How to convert an ndarray back to a buffer/array/…? #29

Open
mathiasbynens opened this issue Apr 2, 2016 · 2 comments
Open

How to convert an ndarray back to a buffer/array/…? #29

mathiasbynens opened this issue Apr 2, 2016 · 2 comments

Comments

@mathiasbynens
Copy link

How to convert an ndarray back to a buffer/array/…? Including all transformations, that is, so not just foo.data.

const fs = require('fs');

const ndarray = require('ndarray');
const show = require('ndarray-show');

const matrix = ndarray([
    0, 0, 0,
    1, 0, 0,
    0, 0, 0
], [3, 3]);
console.log(show(matrix, 2));
/*
 0  0  0
 1  0  0
 0  0  0
*/
console.log('-'.repeat(72));
const modified = matrix.transpose(1, 0);
console.log(show(modified, 2));
/*
 0  1  0
 0  0  0
 0  0  0
*/
console.log('-'.repeat(72));
console.log(modified.data);
/* [
 0, 0, 0,
 1, 0, 0,
 0, 0, 0
] */

// I want to somehow get the transposed matrix as an array or buffer:

/* [
    0, 1, 0,
    0, 0, 0,
    0, 0, 0
]
*/

Is there a better way than .picking and .getting each value individually and manually adding it to an array/buffer? I feel like I’m missing something obvious here…

@letmaik
Copy link

letmaik commented May 4, 2016

@mikolalysenko
Copy link
Member

You can use ndarray-ops or ndarray-unpack to do it.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants