rust_linear_algebra/matrix/transpose.rs
1use super::Matrix;
2
3impl<K> Matrix<K>
4where
5 K: Copy + Default,
6{
7 pub fn transpose(&self) -> Matrix<K> {
8 let mut elements = vec![vec![K::default(); self.rows()]; self.cols()];
9
10 for i in 0..self.rows() {
11 for j in 0..self.cols() {
12 elements[j][i] = self.elements[i][j];
13 }
14 }
15
16 Matrix { elements }
17 }
18}