-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidentity_matrix.py
35 lines (29 loc) · 970 Bytes
/
identity_matrix.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
'''
An identity matrix is defined as a square matrix with 1's running from the top left of the square to the bottom right. The rest are 0's. The identity matrix has applications ranging from machine learning to the general theory of relativity.
Identity Matrix:
-----------------
Input : 4
Output : 1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
Mirror Identity Matrix:
----------------------
Input : 4
Output : 0 0 0 1
0 0 1 0
0 1 0 0
1 0 0 0
'''
# Using smart logic, loops, and algorithms to output the mirror image of an identity matrix
print("\nMirror image of an identity matrix\n")
size = int(input("Input matrix size: "))
# Create matrix
for row in range(0, size):
for col in range(0, size):
# Mirror image of identity matrix occurs when the sum of the row and column is equal matrix index size
if((row + col) == (size-1)):
print("1 ", end = " ")
else:
print("0 ", end = " ")
print("\n")