Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python numpy rotate matrix

>>> m = np.array([[1,2],[3,4]], int)
>>> m
array([[1, 2],
       [3, 4]])
>>> np.rot90(m)
array([[2, 4],
       [1, 3]])
>>> np.rot90(m, 2)
array([[4, 3],
       [2, 1]])
>>> m = np.arange(8).reshape((2,2,2))
>>> np.rot90(m, 1, (1,2))
array([[[1, 3],
        [0, 2]],
       [[5, 7],
        [4, 6]]])
Comment

rotate matrix python

numpy.rot90(array, k=number_rotations, axes=(0, 1))
Comment

Make Rotation matrix in Python

In [x]: theta = np.radians(30)
In [x]: c, s = np.cos(theta), np.sin(theta)
In [x]: R = np.array(((c, -s), (s, c)))
Out[x]: print(R) 
[[ 0.8660254 -0.5      ]
 [ 0.5        0.8660254]]
Comment

matrix rotation in python

def rotate(matrix):
    rows = len(matrix)
    cols = len(matrix[0])
    res = []
    for i in range(cols):
        temp = []
        for j in range(rows):
            temp.append(matrix[j][i])
        res.append(temp[::-1])

    return res


matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
print(rotate(matrix))
Comment

PREVIOUS NEXT
Code Example
Python :: how to create dictionary in python from csv 
Python :: check for double character in a string python 
Python :: lagrange polynomial python code 
Python :: how to download a project from pythonanywhere 
Python :: ffill dataframe python 
Python :: python icon on task bar 
Python :: mode with group by in python 
Python :: python async function 
Python :: hashlib sha 256 
Python :: url encoded path using python 
Python :: can only concatenate str (not "int") to str 
Python :: python run batch file 
Python :: get dict values in list python 
Python :: python pandas shift last column to first place 
Python :: python datetime get date one week from today 
Python :: check if something is nan python 
Python :: sharpdevelop pause python code 
Python :: python random walk 
Python :: python using random module 
Python :: flask blueprint 
Python :: dice roller in python 
Python :: import discord python 
Python :: remove initial space python 
Python :: declare empty var python 
Python :: python private method 
Python :: dot operator in python 
Python :: check if list elememnt in dataframe column 
Python :: Iterate through string backwards in python 
Python :: python dict remove duplicates where items are not the same 
Python :: django oauth toolkit permanent access token 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =