Replies: 5 comments
-
A function Do you have any practical use cases for |
Beta Was this translation helpful? Give feedback.
-
Primarily as a facilitation when generating data to work with. var A = math.range(1, 10).reshape([3, 3]);
var B = math.random(0, 1).reshape([2, 3]);
// this is equal to math.random([2, 3]); Or perhaps even adding this functionality to |
Beta Was this translation helpful? Give feedback.
-
In the past I have used matlab's // f is some interesting function we wish to study
for(var i=0; i<10; i++) {
for(var j=0; j<10; j++) {
for(var k=0; k<10; k++) {
fs.appendLine("myfile.txt", f(i, j, k));
}
}
} Later, // loadMyArray is some function to read a file into an array
var flat = loadMyArray("myfile.txt");
var array = flat.reshape(10, 10, 10);
// Array is now a multidimensional array Came in very handy to reshape data so it could be plotted by matlab. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the examples guys. @patgrasso it would be great if you want to implement |
Beta Was this translation helpful? Give feedback.
-
const pixelData = [255, 255, 255, 255, ....]; // a 1d Buffer array
reshape(pixelData, 20, 20); |
Beta Was this translation helpful? Give feedback.
-
I think it might be useful to have a
reshape()
function that accepts a matrix and a list of dimensions, and formats the matrix to fit the specified dimensions.resize()
does this already, but it doesn't preserve all of the elements.Thoughts? I can start working on it and submit a PR if this sounds appealing.
Beta Was this translation helpful? Give feedback.
All reactions