-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRotateMatrix-numpy.py
More file actions
40 lines (34 loc) · 1.23 KB
/
RotateMatrix-numpy.py
File metadata and controls
40 lines (34 loc) · 1.23 KB
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
# Using numpy Transpose function to solve the problem.
import numpy as np
# Transform list of list as array
arr = np.array([['.','.','.','.','.','.'],
['.','0','0','.','.','.'],
['0','*','0','0','.','.'],
['0','0','0','0','0','.'],
['.','0','0','0','0','0'],
['0','0','0','0','0','.'],
['0','0','0','0','.','.'],
['.','0','0','.','.','.'],
['.','.','.','.','.','.']])
print(arr)
# check if input is n times 90 degrees
while True:
try:
YourInput = int(input("Please input the degree of rotation: "))
if YourInput%90 == 0 and YourInput != 0:
break
print("Oops! That was not valid degree. Try again...")
except ValueError:
print("Oops! That was not valid number. Try again...")
# assign the original array to as working array
WorkingArray = arr
if YourInput >=0:
for n in range(abs(int(YourInput/90))):
# Transpose array and flip
WorkingArray = WorkingArray.T[:,::-1]
print(WorkingArray)
else:
for n in range(abs(int(YourInput/90))):
# Transpose array and flip
WorkingArray = WorkingArray.T[::-1,:]
print(WorkingArray)