I have a n*m
-matrix A
and a n
-dimensional vector b
. I want to scale the i
-th row of my matrix by the i
-th coefficient in my vector b
. Essentially, I'm trying to achieve this:
A[i, :] = A[i, :] / b[i]
Ideally I'd like to do it without using for loops. Here's my code so far:
let res = self.my_vector
.as_ref()
.map(|vector| {
self.my_matrix
.axis_iter(Axis(0))
.zip(vector.iter())
.map(|(a, b)| a.to_owned() / b.sqrt())
})
.map_err(|err| err.clone())
Note that my_vector
is of type std::result::Result<ArrayBase<OwnedRepr<F>, Dim<[usize; 1]>>>
, hence the self.my_vector.as_ref().map(|vector| { ... })
part.
This code outputs std::result::Result<Map<std::iter::Zip<AxisIter<'_, F, Dim<[usize; 1]>>, ndarray::iter::Iter<'_, F, Dim<[usize; 1]>>>, _>
, while I'd like res
to be std::result::Result<Array2<F>>
.
I think I struggle building a 2d
array from this axis_iter
-map
syntax. I tried to add .collect()
but I was told that Array2d
cannot be built from an iterator over elements of Array1d
.
Any help is appreciated
Many thanks in advance