• JSP
  • Struts
  • PHP
  • Java IO
  • Core Java
  • Spring
  • jQuery
  • Servlet
  • SQL Tutorial

  • <

    Numpy Linear Algebra

    NumPy package contains numpy.linalg module that provides all the functionality required for linear algebra.


    numpy.dot() function

    Return dot product of the two arrays.


    
    import numpy as np  
    a = np.array([[100,200],[23,12]])  
    b = np.array([[10,20],[12,21]])  
    dot = np.dot(a,b)  
    print(dot)  
    

    output
    
    [[3400 6200]
     [ 374  712]]
    
    
    The dot product is calculated as:
    
    [100 * 10 + 200 * 12, 100 * 20 + 200 * 21] [23*10+12*12, 23*20 + 12*21] 
    


    numpy.vdot() function

    Return dot product of the two vectors.


    import numpy as np  
    a = np.array([[100,200],[23,12]])  
    b = np.array([[10,20],[12,21]])  
    vdot = np.vdot(a,b)  
    print(vdot)  
    

    output
    
    5528
    
    
    np.vdot(a,b) = 100 *10 + 200 * 20 + 23 * 12 + 12 * 21 = 5528 
    


    numpy.inner() function

    Return Inner product of the two arrays.


    import numpy as np  
    a = np.array([1,2,3,4,5,6])  
    b = np.array([23,23,12,2,1,2])  
    inner = np.inner(a,b)  
    print(inner)  
    
    

    output
    
    130
    
    


    numpy.matmul() function

    Return matrix product of the two arrays.


    
    import numpy as np  
    a = np.array([[1,2,3],[4,5,6],[7,8,9]])  
    b = np.array([[23,23,12],[2,1,2],[7,8,9]])  
    mul = np.matmul(a,b)  
    print(mul)  
    


    numpy determinant

    Computes the determinant of the array.


    
    import numpy as np  
    a = np.array([[1,2],[3,4]])  
    print(np.linalg.det(a)) 
    

    output
    
    -2.0000000000000004
    
    


    numpy.linalg.solve() function

    Solves the linear matrix equation.


    import numpy as np  
    a = np.array([[1,2],[3,4]])  
    b = np.array([[1,2],[3,4]])  
    print(np.linalg.solve(a, b))  
    
    
    

    output
    [[1. 0.]
     [0. 1.]]
    
    


    numpy.linalg.inv() function

    Finds the multiplicative inverse of the matrix.


    
    import numpy as np  
    a = np.array([[1,2],[3,4]])  
    print("Original array:\n",a)  
    b = np.linalg.inv(a)  
    print("Inverse:\n",b)  
    

    output
    
    Original array:
     [[1 2]
     [3 4]]
    Inverse:
     [[-2.   1. ]
     [ 1.5 -0.5]]
    
















    © copyright 2017-2021 Completedone pvt ltd.