Effectively copy matrix values ​​to a new matrix

Is there an efficient built-in method that copies a value from one matrix (e.g. double[,]) to another?

In word order, I am looking for a replacement function below:

    public static double[,]CloneMatrix(double[,] aMatrix)
    {
        var newMatrix = new double[aMatrix.GetLength(0),aMatrix.GetLength(1)];
        for (int i = 0; i < aMatrix.GetLength(0); i++)
        {
            for (int j = 0; j < aMatrix.GetLength(1); j++)
            {
                newMatrix[i, j] = aMatrix[i, j];
            }
        }
        return newMatrix;

    }
+3
source share
2 answers

Use the Clone method:

double[,] result = (double[,])aMatrix.Clone();
+4
source

, (, "" , ) - , ( ). , double[][] , .

0

Source: https://habr.com/ru/post/1780999/


All Articles