This project has moved and is read-only. For the latest updates, please go here.

Modulo operator on matrix

Jan 17, 2011 at 4:20 AM

Hi - Is there a modulus operator on a matrix? More specifically, I'm creating a matrix:

 var matrixA = new DenseMatrix(new[,] { { 5.0, 8.0 }, { 17.0, 3.0 } });
and I would like to perform the following operation:
var matrixB = matrixA % 26; 
or something to that effect. The application is for encryption (Hill Cipher).
Jan 17, 2011 at 12:41 PM

Hi Mike,

There isn't. I'll add it to the to do list.

In the meantime, you could use an extenstion method such as:

public static Matrix Mod(this DenseMatrix matrix, int mod)
    var result = (DenseMatrix)matrix.Clone();

    Parallel.For(0, result.Data.Length, index => result.Data[index] %= mod);

    return result;
Then the usage would be:

var matrixB = matrixA.Mod(26);


Jan 17, 2011 at 12:41 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.