Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Numpy Beginner's Guide (Update)
  • Toc
  • feedback
Numpy Beginner's Guide (Update)

Numpy Beginner's Guide (Update)

By : Ivan Idris
2 (1)
close
Numpy Beginner's Guide (Update)

Numpy Beginner's Guide (Update)

2 (1)
By: Ivan Idris

Overview of this book

This book is for the scientists, engineers, programmers, or analysts looking for a high-quality, open source mathematical library. Knowledge of Python is assumed. Also, some affinity, or at least interest, in mathematics and statistics is required. However, I have provided brief explanations and pointers to learning resources.
Table of Contents (16 chapters)
close
14
C. NumPy Functions' References
15
Index

Time for action – computing the pseudo inverse of a matrix

Let's compute the pseudo inverse of a matrix:

  1. First, create a matrix:
    A = np.mat("4 11 14;8 7 -2")
    print("A\n", A)

    The matrix we created looks like the following:

    A
    [[ 4 11 14]
     [ 8  7 -2]]
    
  2. Calculate the pseudo inverse matrix with the pinv() function:
    pseudoinv = np.linalg.pinv(A)
    print("Pseudo inverse\n", pseudoinv)

    The pseudo inverse result is as follows:

    Pseudo inverse
    [[-0.00555556  0.07222222]
     [ 0.02222222  0.04444444]
     [ 0.05555556 -0.05555556]]
    
  3. Multiply the original and pseudo inverse matrices:
    print("Check", A * pseudoinv)

    What we get is not an identity matrix, but it comes close to it:

    Check [[  1.00000000e+00   0.00000000e+00]
     [  8.32667268e-17   1.00000000e+00]]
    

What just happened?

We computed the pseudo inverse of a matrix with the pinv() function of the numpy.linalg module. The check by matrix multiplication resulted in a matrix that is approximately an identity matrix (see...

bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete