Comments (5)
Hi! You could do something like this:
let mut mat = Matrix4x3::repeat(1);
let vec = RowVector3::new(1, 2, 3);
mat.row_iter_mut().for_each(|mut row| row -= vec);
from nalgebra.
@sebcrozet Thanks for your advice, but according to your advide, I was using RowVector
to construct a vector, but it seems not right
let m = rs.row_mean();
let _v = m.as_slice().to_vec();
for row in rs.row_iter_mut(){
row = row - RowVector::from_vec(_v);
}
rs
is a Matrix.
I cannot fix this ...
from nalgebra.
The error here originates from the fact that the compiler doesn’t know what kind of row vector you want (dynamically sized? staticaly sized?) So you can for example do DRowVector::from_vec(_v)
instead, where DRowVector
is a dynamically sized row vector.
Anyway, you don’t need that conversion at all. Your variable m
is already a row vector (because row_mean
returns a row vector). So the to_vec/from_vec
are not needed.
In addition, you can’t do row = row - RowVector::from_vec(_v)
because row
is a matrix view (whereas the result of a binary operation must be a whole new vector, it can’t be a view on an existing vector). So you need to apply the subtraction in-place:
let mean = rs.row_mean();
for mut row in rs.row_iter_mut() {
row -= &mean;
}
from nalgebra.
@sebcrozet Thanks for your help!
from nalgebra.
@sebcrozet Sorry but I didn't found the DRowVector
type. Maybe we just left out pub type DRowVector<T>=Matrix<T, U1, Dyn, VecStorage<T, U1, Dyn>>;
somewhere?
Regarding another question, though which I'm not sure if worth a new issue, I'm trying to subtracting a row from another row within the same matrix. Of course this can't be written as in other languages because of rust's borrow checker. So I have to copy the subtractee into a new DRowVector
(which led me to this issue) like this:
pub type DRowVector<T>=Matrix<T, U1, Dyn, VecStorage<T, U1, Dyn>>;
let t: DRowVector<f64> = mat.row(i-1).into();
mat.row_mut(i).sub_assign(t);
which seems to be redundant. Is there already a zero-copy way to do this operation, or should we add something like split_at_mut
?
from nalgebra.
Related Issues (20)
- Wrong eigenvector sorting in nalgebra::SymmetricEigen, while correct in nalgebra_lapack::SymmetricEigen HOT 1
- Make some RealField functions const HOT 1
- `tr_solve_upper_triangular` proptest failure
- Hash for Matrix doesn't match `Borrow<[[T; R]; C]>` semantics
- Cannot compute the SVD of an empty matrix. HOT 2
- Matrix Display output alignment is not Unicode-aware HOT 4
- Multiply matrix by vector row-wise HOT 6
- matrix literals or const constructors HOT 1
- `normalize` docs need expansion HOT 1
- Test flake in `f64::symmetric_eigen`
- Unit Quaternion logarithm inconsistent with exp HOT 1
- Matrix Views: non contiguous/regular slices
- Minimizing trait bound complexity when working with dimensional generics HOT 3
- SVD Computes Wrong Singular Values for Very Small-Valued Matrices HOT 1
- Make nalgebra_lapack::qr::QRScalar trait public
- Homographic transform via SVD/DLT - is it broken or am I doing it wrong?
- Inconsistency between Numpy/MATLAB and and nalgebra HOT 2
- Export crates used in public APIs
- unit quaternions and orthonormal matrices are only closed under successive multiplications in theory HOT 1
- Memory leak in generic_resize/reallocate_copy
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nalgebra.