code.py 836 Bytes
Newer Older
RODIONOV Sergey's avatar
RODIONOV Sergey committed
1
#!/usr/bin/env python
RODIONOV Sergey's avatar
RODIONOV Sergey committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
import numpy as np
import sys
import argparse
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt

# Slow matrix multiplication
def mult(A,B):
    n = len(A);
    C = np.zeros((n,n))
    for i in range(n):
        for j in range(n):
            for k in range(n):
                C[i,j] += A[i,k] * B[k,j]                 
    return C

# Parse command line arguments
parser = argparse.ArgumentParser()
parser.add_argument("seed",        help="Random seed", type=int);
parser.add_argument("-size",       help="Size of matrix", type=int, default=100);
args = parser.parse_args()

np.random.seed(args.seed)
A = np.random.rand (args.size, args.size)
B = np.random.rand (args.size, args.size)
C = mult(A,B)

plt.matshow(C)

fname = "out_" + str(args.seed) + ".png"
plt.savefig(fname)
print (fname)