Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

matrix transpose c#

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

PREVIOUS NEXT
Code Example
Csharp :: restrictions 
Csharp :: add one to one relationship entity framework 
Csharp :: math in c# 
Csharp :: delete all fields that start with mongo 
Csharp :: math.pow in C# using loop 
Csharp :: static keyword 
Csharp :: c# collection of generic classes 
Csharp :: what dotnet command does 
Csharp :: what is int.parse in c# 
Csharp :: how to add object in dictionary in c# 
Csharp :: Entity framwork update parent entity added new sub entity 
Csharp :: c# how to refresh input field 
Csharp :: unity SceneTemplatePipeline 
Csharp :: jq map over array 
Csharp :: index list c# 
Csharp :: txt.att.net not working 2021 
Csharp :: Unity Scene Load by BuildIndex 
Csharp :: asp.net core 6 get current culture in controller 
Csharp :: Xamarin forms XAML change value 
Csharp :: Boolean Literals 
Csharp :: how to add extra window to wpf 
Csharp :: Include multiple siblings at the Level 
Csharp :: F# tuple get item 
Csharp :: C# return dictionary string/integer from comparison of List and Array 
Csharp :: Event that fires during DataGridViewComboBoxColumn SelectedIndexChanged 
Csharp :: c# loop datatable column names convert to list 
Csharp :: c# ile ürün çekme - htmlagilitypack 
Csharp :: c# statements 
Csharp :: store file in DB 
Csharp :: check if variable less than in f# 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =