Thursday, July 4, 2024
HomeLanguagesPythonRotate-matrix module in Python

Rotate-matrix module in Python

The rotate-matrix is an interesting new python module, which allows conversion of a matrix(2-D array) into either clockwise rotation or anti-clockwise rotation. It at present consists of only two methods. You can loop through these methods for ‘n’ number of rotations.

Installation

This module doesn’t come in-built with python but can be installed using the following command:

pip install rotate-matrix

 Functions

1) clockwise(): As obviously the name suggests, this function is used to rotate the matrix clockwise.

Syntax: clockwise(matrix)

Parameter: Takes matrix as parameter which is of type list.

Return Value: passes the clock-wised rotated version of the matrix

    Example:

Python3




import rotate_matrix
 
mat = [[5, 2, 6], [8, 2, 9], [3, 6, 7], [3, 6, 2]]
 
print(rotate_matrix.clockwise(mat))


 Output:

[(6, 9, 7, 2), (2, 2, 6, 6), (5, 8, 3, 3)]

2) anti_clockwise(): This function of this module rotates the given matrix anti-clockwise.

Syntax: anti_clockwise(matrix)

Parameter: Takes matrix as parameter which is of type list 

Return Value: passes the anti-clockwise rotated version of the matrix

Example:

Python3




import rotate_matrix
 
mat = [[5, 2, 6], [8, 2, 9], [3, 6, 7], [3, 6, 2]]
 
print(rotate_matrix.anti_clockwise(mat))


Output:

[(3, 3, 8, 5), (6, 6, 2, 2), (2, 7, 9, 6)]

Shaida Kate Naidoo
am passionate about learning the latest technologies available to developers in either a Front End or Back End capacity. I enjoy creating applications that are well designed and responsive, in addition to being user friendly. I thrive in fast paced environments. With a diverse educational and work experience background, I excel at collaborating with teams both local and international. A versatile developer with interests in Software Development and Software Engineering. I consider myself to be adaptable and a self motivated learner. I am interested in new programming technologies, and continuous self improvement.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments