Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
@mathiasbynens

Description

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...

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

        AltStyle によって変換されたページ (->オリジナル) /