From 661393483596850c6646253999e6298d6654c2d3 Mon Sep 17 00:00:00 2001 From: Kartikeya Gupta <55078693+Kartikeya006@users.noreply.github.com> Date: Tue, 20 Oct 2020 17:21:06 +0530 Subject: [PATCH] Rotates an Entered Matrix --- Python-programming-1/matrix_clock_rotation.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Python-programming-1/matrix_clock_rotation.py diff --git a/Python-programming-1/matrix_clock_rotation.py b/Python-programming-1/matrix_clock_rotation.py new file mode 100644 index 000000000..8851f84dc --- /dev/null +++ b/Python-programming-1/matrix_clock_rotation.py @@ -0,0 +1,25 @@ +# Rotate a Matrix by 90 degrees clockwise +import numpy as np +a = int(input("Enter Index of matrix:-")) +b = [] +print("Enter the Matrix Element Rowwise:-") +for i in range(a): + c = [] + for j in range(a): + c.append(int(input(f"Enter the {i+1}row {j+1}column Entry:-"))) + b.append(c) + + +def print_matrix(z): # This function print the values of list in the list in form of Matrix + for i in range(len(z)): + for j in range(len(z)): + print(z[i][j], end=" ") + print() + + +print("Original Matrix is:-") +print_matrix(b) +degrees = {"90": 1, "180": 2, "270": 3} +c = np.rot90(b, 4-degrees["90"]) +print("Matrix After Rotation(Clockwise):-") +print_matrix(c)