Пример #1
0
def prob4():
    """If no command line argument is given, print "No Input."
    If anything other than "matrices.npz is given, print "Incorrect Input."
    If "matrices.npz" is given as a command line argument, use functions
    from the provided 'matrix_multiply' module to load two matrices, then
    time how long each method takes to multiply the two matrices together.
    Print your results to the terminal.
    """
    if len(sys.argv) < 2:
        print 'No Input.'
    else:
        if sys.argv[1] != 'matrices.npz':
            print 'Incorrect Input.'
        else:
            a, b = matrix_multiply.load_matrices(sys.argv[1])
            start = time.time()
            matrix_multiply.method1(a, b)
            print 'Method 1 took {} sec.'.format(time.time() - start)
            start = time.time()
            matrix_multiply.method2(a, b)
            print 'Method 2 took {} sec.'.format(time.time() - start)
            start = time.time()
            matrix_multiply.method3(a, b)
            print 'Method 3 took {} sec.'.format(time.time() - start)

    pass
Пример #2
0
def prob4():
    """If no command line argument is given, print "No Input."
    If anything other than "matrices.npz is given, print "Incorrect Input."
    If "matrices.npz" is given as a command line argument, use functions
    from the provided 'matrix_multiply' module to load two matrices, then
    time how long each method takes to multiply the two matrices together.
    Print your results to the terminal.
    """
    if len(sys.argv) < 2:
        print("No Input.")
    elif sys.argv[1] != "matrices.npz":
        print("Incorrect Input.")
    else:
        A,B = matrix_multiply.load_matrices("matrices.npz")
        
        start = time.time()
        matrix_multiply.method1(A,B)
        end = time.time()
        method1Time = end - start

        start = time.time()
        matrix_multiply.method2(A,B)
        end = time.time()
        method2Time = end - start

        start = time.time()
        matrix_multiply.method3(A,B)
        end = time.time()
        method3Time = end - start

        print("time for method1 is: " + str(method1Time))
        print("time for method2 is: " + str(method2Time))
        print("time for method3 is: " + str(method3Time))
Пример #3
0
def prob4():
    """If no command line argument is given, print "No Input."
    If anything other than "matrices.npz is given, print "Incorrect Input."
    If "matrices.npz" is given as a command line argument, use functions
    from the provided 'matrix_multiply' module to load two matrices, then
    time how long each method takes to multiply the two matrices together.
    Print your results to the terminal.
    """
    if len(sys.argv) < 2:
        print 'No Input.'
    else:
        if sys.argv[1] != 'matrices.npz':
            print 'Incorrect Input.'
        else:
            a,b = matrix_multiply.load_matrices(sys.argv[1])
            start = time.time()
            matrix_multiply.method1(a,b)
            print 'Method 1 took {} sec.'.format(time.time()-start)
            start = time.time()
            matrix_multiply.method2(a,b)
            print 'Method 2 took {} sec.'.format(time.time()-start)
            start = time.time()
            matrix_multiply.method3(a,b)
            print 'Method 3 took {} sec.'.format(time.time()-start)
            
            
    
    pass
Пример #4
0
def prob4():
    """If no command line argument is given, print "No Input."
    If anything other than "matrices.npz is given, print "Incorrect Input."
    If "matrices.npz" is given as a command line argument, use functions
    from the provided 'matrix_multiply' module to load two matrices, then
    time how long each method takes to multiply the two matrices together.
    Print your results to the terminal.
    """
    if len(sys.argv) == 1:
        print "No Input."

    elif sys.argv[1] == "matrices.npz":
        A, B = matrix_multiply.load_matrices("matrices.npz")
        
        before = time.time()
        matrix_multiply.method1(A,B)
        after = time.time()
        method1_time = after - before
        
        before = time.time()
        matrix_multiply.method2(A,B)
        after = time.time()
        method2_time = after - before
        
        before = time.time()
        matrix_multiply.method3(A,B)
        after = time.time()
        method3_time = after - before
        
        print "Method 1: " + str(method1_time)
        print "Method 2: " + str(method2_time)
        print "Method 3: " + str(method3_time)
        
    else:
        print "Incorrect Input"
Пример #5
0
def prob4():
    """If no command line argument is given, print "No Input."
    If anything other than "matrices.npz is given, print "Incorrect Input."
    If "matrices.npz" is given as a command line argument, use functions
    from the provided 'matrix_multiply' module to load two matrices, then
    time how long each method takes to multiply the two matrices together.
    Print your results to the terminal.
    how do I load the files correctly? how do I print to the terminal?
    """
    if len(sys.argv) <2 : 
        print "No Input."
    elif sys.argv[1] == 'matrices.npz':

        A,B = matrix_multiply.load_matrices('matrices.npz')
        start1 = time.time()
        matrix_multiply.method1(A,B)
        end1 = time.time()
        C =  (end1-start1)
        #time1 = str(end1-start1)

        start2 = time.time()
        matrix_multiply.method2(A,B)
        end2 = time.time()
        #print (end2-start2)
        D = (end2-start2)
        #time2 = str(end2 -time2)

        start3 = time.time()
        matrix_multiply.method3(A,B)
        end3 = time.time()
        E = (end3-start3)
        #print (end3-start3)

        #time3 = str(end3-start3)

        print "time for method 1: " + str(C)
        print "time for method 2: " + str(D)
        print "time for method 3: " + str(E)
    else :
        print "Incorrect Input."
Пример #6
0
import matrix_multiply
import time

output = []

if len(sys.argv) == 1:
    print "No Input"
elif sys.argv[1] != "matrices.npz":
    print "Invalid Input"
else:    
    A,B = matrix_multiply.load_matrices(sys.argv[1])
    
    m1_time1 = time.time()
    matrix_multiply.method1(A,B)
    m1_time2 = time.time()
    
    output.append(m1_time2 - m1_time1)
    
    m2_time1 = time.time()
    matrix_multiply.method2(A,B)
    m2_time2 = time.time()
    
    output.append(m2_time2 - m2_time1)
    
    m3_time1 = time.time()
    matrix_multiply.method3(A,B)
    m3_time2 = time.time()
    
    output.append(m3_time2 - m3_time1)
    
    print output