import math def inner(l1, l2): result = 0 for i in range(len(l1)): result = result + l1[i]*l2[i] return result def transpose(m1): result = [] for i in range(len(m1[0])): resl = [] for x in m1: #print(x) resl.append(x[i]) #print(resl) result.append(resl) return result def multi(obj,m): tm = transpose(m) result = [] for x in obj: resl = [] for i in tm: #print(x) #print(i) resl.append(inner(x,i)) result.append(resl) return result obj = [[2,2,1],[4,2,1],[2,4,1]] def T(obj,x,y): L = [[1,0,0],[0,1,0],[x,y,1]] return multi(obj,L) def S(obj,x,y): L = [[x,0,0],[0,y,0],[0,0,1]] return multi(obj,L) def R(obj, theta): L = [[math.cos(theta), math.sin(theta), 0],[-math.sin(theta), math.cos(theta),0],[0,0,1]] return multi(obj,L) print(T(obj,3,2)) print(S(obj,2,1/2)) print(R(obj,math.pi/2))