Scipy - Square matrix - Determinant, Eigen values and Eigen vectors

 # Scipy - Determinant of a square array

# Scipy - Eigen values and Eigen vectors


#importing the scipy and numpy packages


from scipy import linalg

import numpy as np

import random


# Creating a random 2d array object of size 3 x 3

A = np.random.randint(10, size=(2,2))


# Calculating the determinant of a square matrix

DA = linalg.det(A)


#printing the result array

print("Given square array")

print(A)


print("Determinant of the square array")

print(int(DA))


# Calling the eigen function

eig_val, eig_vect = linalg.eig(A)


# Printing the eigen values

print("Eigen values : ")

print(eig_val)


# Printing the eigen vectors

print("Eigen vectors : ")

print(eig_vect)



"""


Sample output


>python 8_6_scipy2.py

Given square array

[[0 5]

 [2 5]]

 

Determinant of the square array

-10


Eigen values :

[-1.53112887+0.j  6.53112887+0.j]


Eigen vectors :

[[-0.9561723  -0.60788018]

 [ 0.2928046  -0.79402877]]

 

"""


No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu