Search
 
SCRIPT & CODE EXAMPLE
 

RUST

what is the transpose of a matrix

The transpose of a matrix is just a flipped version of 
the original matrix. We can transpose a matrix by switching 
its rows with its columns. The original rows become the new columns
and the original columns become the new rows.
We denote the transpose of matrix A by AT. 

For example:
	1 2 3                      1 4 7
A = 4 5 6       then      AT = 2 5 8
    7 8 9                      3 6 9
    
Similarly if 

B = 1 2 3       then      BT = 1 4
    4 5 6                      2 5 
                               3 6
Comment

Transpose a matrix

// Transpose a matrix
fn matrix_transpose(m: Vec<Vec<i32>>) -> Vec<Vec<i32>> {
    let mut t = vec![Vec::with_capacity(m.len()); m[0].len()];
    for r in m {
        for i in 0..r.len() {
            t[i].push(r[i]);
        }
    }
    t
}

fn main() {
    let m = vec![vec![1, 2, 3], vec![4, 5, 6], vec![7, 8, 9]];
    println!("Matrix:
{:?}", m);
    let t = matrix_transpose(m);
    println!("Transpose:
{:?}", t);
}
Comment

matrix transpose

public class Solution 
{
    public int[][] Transpose(int[][] matrix) 
    {
        var trans = GenerateArray(matrix[0].Length,matrix.Length,0);
        
        for(var i=0; i<matrix.Length;i++)
        {
            for(var j=0; j<matrix[0].Length;j++)
            {
                trans[j][i] = matrix[i][j];
            }
        }
        return trans;
    }
    public static T[][] GenerateArray<T>(int row, int Col,T value)
    {
        var arr = new T[row][];

        for (int i = 0; i < row; i++)
        {
            arr[i] = new T[Col];
            for (int j = 0; j < Col; j++)
            {
                arr[i][j] = value;
            }
        }
        return arr;
    }
}
Comment

transpose of matrix

#include<stdio.h>
void main(){
    int row,column,i,j,mat[100][100],tra[100][100];

    printf("Enter number of rows of matrix : ");
    scanf("%d",&row);
    printf("Enter number of columns of matrix : ");
    scanf("%d",&column);
    
    printf("#### Matrix ####
");
    for(i=0;i<row;i++){
        for(j=0;j<column;j++){
            printf("Enter element a %d%d : ",i+1,j+1);
            scanf("%d",&mat[i][j]);
        }
    }

    for(i=0;i<row;i++){
        for(j=0;j<column;j++){
            tra[i][j] = mat[j][i];
        }
    }
    
    for(i=0;i<row;i++){
        for(j=0;j<column;j++){
            printf("%d ",tra[i][j]);
        }
        printf("
");
    }
    
}
Comment

PREVIOUS NEXT
Code Example
Rust :: rustlang char array 
Rust :: regex in rust 
Rust :: string and str to string rust 
Rust :: rust compiler 
Rust :: rust undefined size array 
Rust :: armanriazi•rust•box•vs•refcell 
Rust :: stringify! in rust 
Rust :: armanriazi•rust•error•the trait `Binary` is not implemented for `f64` 
Rust :: rust named tuple 
Rust :: armanriazi•rust•error•E0502•cannot borrow `s` as mutable because it is also borrowed as immutable 
Rust :: armanriazi•rust•comparison•iter•vs•for 
Rust :: rust print i8 
Rust :: rust currying, preset some arguments 
Rust :: Transpose matrix, pass-by-reference to function 
Rust :: armanriazi•rust•error•already borrowed: BorrowMutError 
Lua :: lua string.split 
Lua :: lua math floor 
Lua :: how to print hello in lua 
Lua :: lua last item in table 
Lua :: roblox random brick colour 
Lua :: what is script.Parent? 
Lua :: lua list of all keys 
Lua :: table.find lua 
Lua :: lua print table 
Lua :: run a function in lua 
Lua :: insert item array pico8 
Lua :: lua print hi 
Matlab :: matlab number to string 
Matlab :: matlab what comes instead of drawmode 
Basic :: powershell how to removve only empty direcoties 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =