Skip to content

Instantly share code, notes, and snippets.

Created December 2, 2013 22:39
Show Gist options
  • Save anonymous/7760387 to your computer and use it in GitHub Desktop.
Save anonymous/7760387 to your computer and use it in GitHub Desktop.
// return C = A * B
public static double[][] multiply(double[][] A, double[][] B) {
int mA = A.length;
int nA = A[0].length;
int mB = B.length;
int nB = A[0].length;
if (nA != mB) throw new RuntimeException("Illegal matrix dimensions.");
double[][] C = new double[mA][nB];
for (int i = 0; i < mA; i++)
for (int j = 0; j < nB; j++)
for (int k = 0; k < nA; k++)
C[i][j] += (A[i][k] * B[k][j]);
return C;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment