How to reshape a dmatrix? #1408
Unanswered
DennisZhangOiler
asked this question in
Q&A
Replies: 1 comment
-
Hey, I'm not super familiar with nalgebra and maybe there exist a simpler method but if you use the generic interface you can write: use nalgebra::{DMatrix, Dyn, SMatrix, Const};
fn main() {
// for dynamical sized stuff
let mut x = DMatrix::<f64>::zeros(10, 2);
let mut x = x.reshape_generic(Dyn(5), Dyn(4)); // works
let mut x = x.reshape_generic(Dyn(2), Dyn(4)); // does not work but will be checked at run time
let (n_row, n_col) = (5, 4);
let mut x = x.reshape_generic(Dyn(n_row), Dyn(n_col)); // works
// for static sized stuff
let mut y= SMatrix::<f64, 3, 4>::zeros();
let mut y = y.reshape_generic(Const::<6>, Const::<2>); // works
// let mut y = y.reshape_generic(Const::<6>, Const::<1>); // does not work and you compile can already catch it
let (n_row, n_col) = (6, 2);
let mut y = y.reshape_generic(Const::<n_row>, Const::<n_col>); // does not work, since variables are not constant. You could use const generics.
} In the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I am a newbie to math and nalgebra, I have some code written in numpy and I want to translate into nalgebra, how to do np.reshape in nalgebra?
Beta Was this translation helpful? Give feedback.
All reactions