Book Image

NumPy: Beginner's Guide

By : Ivan Idris
Book Image

NumPy: Beginner's Guide

By: Ivan Idris

Overview of this book

Table of Contents (21 chapters)
NumPy Beginner's Guide Third Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
NumPy Functions' References
Index

Time for action – calculating the determinant of a matrix


To calculate the determinant of a matrix, follow these steps:

  1. Create the matrix:

    A = np.mat("3 4;5 6")
    print("A\n", A)

    The matrix we created appears as follows:

    A
    [[ 3.  4.]
     [ 5.  6.]]
    
  2. Compute the determinant with the det() function:

    print("Determinant", np.linalg.det(A))

    The determinant appears as follows:

    Determinant -2.0
    

What just happened?

We calculated the determinant of a matrix with the det() function from the numpy.linalg module (see determinant.py):

from __future__ import print_function
import numpy as np

A = np.mat("3 4;5 6")
print("A\n", A)

print("Determinant", np.linalg.det(A))