Exemple #1
0
 def test_Q2(self):
     a = np.arange(25).reshape(5, 5)
     b = np.array([1., 5, 10, 15, 20])
     c = md.matrix_divide(a, b)
     d = np.array([[0., 1., 2., 3., 4.], [1., 1.2, 1.4, 1.6, 1.8],
                   [1., 1.1, 1.2, 1.3, 1.4], [1., 1.067, 1.133, 1.2, 1.267],
                   [1., 1.05, 1.1, 1.15, 1.2]])
     self.assertTrue(np.array_equal(c, d))
Exemple #2
0
 def test_Q2(self):
     a = np.arange(25).reshape(5, 5)
     b = np.array([1., 5, 10, 15, 20])
     c = md.matrix_divide(a,b)
     d = np.array([[ 0., 1., 2., 3., 4.], 
                   [1., 1.2, 1.4, 1.6, 1.8], 
                   [1., 1.1, 1.2, 1.3, 1.4], 
                   [ 1., 1.067, 1.133, 1.2, 1.267], 
                   [ 1., 1.05, 1.1, 1.15, 1.2]])
     self.assertTrue(np.array_equal(c,d))
Exemple #3
0
    print "\n The answer of Question 1, (b) is"
    print m2day.make_2D_array(5, 3, 1, 15)[:, 1:2]

    #c
    print "\n The answer of Question 1, (c) is"
    print m2day.make_2D_array(5, 3, 1, 15)[1:4, :3]

    #d
    print "\n The answer of Question 1, (d) is"
    print m2day.make_2D_array(5, 3, 1, 15).T.reshape(1,15)[0][2:11]

    # Question 2
    a = np.arange(25).reshape(5, 5)
    b = np.array([1., 5, 10, 15, 20])
    print "\n The answer of Question 2 is"
    print md.matrix_divide(a,b)

    # Question 3
    print "\n The answer of Question 3 is"
    print cl5.close_to_5()

    # Question 4
    print "\n Generating plot.........."
    mask = mand.mandelbort_set(-2, 1, -1.5, 1.5)
    print "\n The plot of question 4 is saved as 'mandelbrot.png' in the current dictory."
    plt.imshow(mask.T, extent=[-2, 1, -1.5, 1.5])
    plt.gray()
    plt.savefig('mandelbrot.png')

except KeyboardInterrupt, ValueError:
    print "\n Interrupted!"