Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The NumPy library is very helpful for solving linear systems in python. For how to install NumPy look here

Info
titleImporting NumPy

All the code-snippets below has numpy importet as np. To learn how see the installation of NumPy

Matrixes in Python


Code Block
languagepy
titleCreating a matrix
a = np.array([[1,2],[3,4]])

...

Code Block
languagepy
titleEigenvalues and eigenvectors
np.linalg.eig(a) # where a is a square matrix


#returns two arrays [v,w]
#v containing the eigenvalues of a
#w containing the eigenvectors of a

...


Code Block
languagepy
titleDeterminant
np.linalg.det(a) # where a is a square matrix


#returns the determinant of the matrix a

...

info
Code Block
languagepy
titleSolving set of equations
import numpy as np

# Solving following system of linear equation
# 5a + 2b = 35
# 1a + 4b = 49

a = np.array([[5, 2],[1,4]]) # Lefthand-side of the equation
b = np.array([35, 94]) #Righthand-side

print(np.linalg.solve(a,b)) #Printing the solution



Relaterte artikler

Content by Label
showLabelsfalse
max5
spacesimtsoftware
showSpacefalse
sortmodified
reversetrue
typepage
cqllabel = "python" and type = "page" and space = "imtsoftware"
labelspython

...