You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For multi dimensional arrays in JS this is how forEach works:
e.g.
let ar1 = [1];
let ar2 = [2];
let arr = [ ar1, ar2 ];
arr.forEach( el => { /** el will equal ar1 or ar2 array object */ } );
In Mathjs the matrix().forEach returns the deepest/innermost element:
e.g.
let ar1 = [1];
let ar2 = [2];
let arr = matrix([ ar1, ar2 ]);
arr.forEach( el => { /** el will equal the number 1 or 2. NOT [1] or [2] */ } );
Right now if I want to loop through the element with the JS behavior I have to grab the hidden matrix array member "_data" which I assume is "wrong".
Please add some support to allow JS style looping through matrix elements.
This could be "easily" done by adding an optional/default parameter to the matrix.forEach method. Maybe "useJSBehavior" defaulted to false?
e.g.
arr.forEach( el => { /** el will equal the array [1] or [2]. */ }, true);
The text was updated successfully, but these errors were encountered:
The idea of the Matrix classes is that they handle multi dimensional arrays. The map and forEach methods indeed loop over all elements and provide you with the index of the element which is typically not a single number but for example the row and column index. You should not see a Matrix as an Array containing Arrays, but really as a matrix with cells having a row and column index. The current implementation internally uses nested arrays but that could theoretically change, and there should be no need to utilize that. For example SparseMatrix does have a different internal structure without nested arrays.
If you do need an array containing arrays, I think it's best to simply use a plain Array for that (or rethink your approach ;) ).
For multi dimensional arrays in JS this is how forEach works:
e.g.
let ar1 = [1];
let ar2 = [2];
let arr = [ ar1, ar2 ];
arr.forEach( el => { /** el will equal ar1 or ar2 array object */ } );
In Mathjs the matrix().forEach returns the deepest/innermost element:
e.g.
let ar1 = [1];
let ar2 = [2];
let arr = matrix([ ar1, ar2 ]);
arr.forEach( el => { /** el will equal the number 1 or 2. NOT [1] or [2] */ } );
Right now if I want to loop through the element with the JS behavior I have to grab the hidden matrix array member "_data" which I assume is "wrong".
Please add some support to allow JS style looping through matrix elements.
This could be "easily" done by adding an optional/default parameter to the matrix.forEach method. Maybe "useJSBehavior" defaulted to false?
e.g.
arr.forEach( el => { /** el will equal the array [1] or [2]. */ }, true);
The text was updated successfully, but these errors were encountered: