Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

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

transpose Matrix

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
Csharp :: c# reflection create generic type 
Csharp :: using statement c# 
Csharp :: How to invoke an AWS Lambda function asynchronously 
Csharp :: user input to array object c# 
Csharp :: if else c# 
Csharp :: assert throw 
Csharp :: linq where condition c# 
Csharp :: c# list initialize 
Csharp :: one line condition c# 
Csharp :: pork hub 
Csharp :: get camera position unity 
Csharp :: unity image button 
Csharp :: json serialize object capitalization config 
Csharp :: list equals in order c# 
Csharp :: how to c# 
Csharp :: read only variable in c# 
Csharp :: linq query to fetch parent child data from same table in c# 
Csharp :: mvc form name 
Csharp :: 40/100 percentage 
Csharp :: c# param exception 
Csharp :: cannot convert from group method to threadstart C# 
Csharp :: C# EDSDK control lens 
Csharp :: datareader get field names 
Csharp :: C# Search in JSON without deserialization 
Csharp :: c# registrykey is null 
Csharp :: how to make build events always run visual studio 
Csharp :: how to call void unity 
Csharp :: skrivetækning 
Csharp :: unrecognized escape sequence c# connection string 
Csharp :: UPA Error 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =