-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathnumpy_linear_algebra.py
54 lines (35 loc) · 1.38 KB
/
numpy_linear_algebra.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""
Problem Statement
The NumPy module also comes with a number of built-in routines for linear algebra calculations. These can be found in the sub-module linalg.
linalg.det
The linalg.det tool computes the determinant of an array.
print numpy.linalg.det([[1 , 2], [2, 1]]) #Output : -3.0
linalg.eig
The linalg.eig computes the eigenvalues and right eigenvectors of a square array.
vals, vecs = numpy.linalg.eig([[1 , 2], [2, 1]])
print vals #Output : [ 3. -1.]
print vecs #Output : [[ 0.70710678 -0.70710678]
# [ 0.70710678 0.70710678]]
linalg.inv
The linalg.inv tool computes the (multiplicative) inverse of a matrix.
print numpy.linalg.inv([[1 , 2], [2, 1]]) #Output : [[-0.33333333 0.66666667]
# [ 0.66666667 -0.33333333]]
Other routines can be found here
Task
You are given a square matrix A with dimensions NXN. Your task is to find the determinant.
Input Format
The first line contains the integer N.
The next N lines contains the N space separated elements of array A.
Output Format
Print the determinant of A.
Sample Input
2
1.1 1.1
1.1 1.1
Sample Output
0.0
"""
import numpy
N = input()
A = numpy.array([map(float,raw_input().split()) for _ in xrange(N)])
print numpy.linalg.det(A)