make efficient the copy of symmetric matrix in c#

后端 未结 3 1732
伪装坚强ぢ
伪装坚强ぢ 2020-12-03 16:23

I want to store in an array a symmetric matrix

for a matrix I was doing this

    double[,] mat = new double[size,size];
    for (int i = 0; i < s         


        
3条回答
  •  被撕碎了的回忆
    2020-12-03 16:57

    If n is the size of the square matrix, you need n * (n + 1) / 2 total values for a symmetric matrix. This is the sum of 1 + 2 + 3 + ... (n - 2) + (n - 1) + n.

    A word of caution, though, it's going to be a big pain to be always trying to calculate the correct index for a given row and column, and I'd only move away from the more intuitive 2D array if the matrices are going to be large, and memory is going to be an issue.

提交回复
热议问题