def __mul__(self, other): # tuple mult if isinstance(other, Tuple): j = [ sum([x[0] * x[1] for x in zip(self.getRow(i), [other.x, other.y, other.z, other.w])]) for i in range(0,4) ] return Tuple(*j) # matrix mult elif isinstance(other, matrix): newMatrix = matrix(self.rows, self.columns) for r in range(self.rows): for c in range(self.columns): newMatrix[r,c] = sum([ x[0] * x[1] for x in zip( self.getRow(r), other.getColumn(c))]) return newMatrix
def step_impl(context): context.a = Tuple(4.3, -4.2, 3.1, 1.0)
def step_impl(context): context.a2 = Tuple(-2,3,1,0)
def step_impl(context): assert context.a1 + context.a2 == Tuple(1,1,6,1)
def step_impl(context): assert context.a / 2 == Tuple(0.5, -1, 1.5, -2)
def step_impl(context): context.a1 = Tuple(3,-2,5,1)
def step_impl(context): assert context.a * 3.5 == Tuple(3.5, -7, 10.5, -14)
def step_impl(context): print(context.a * 0.5) assert context.a * 0.5 == Tuple(0.5, -1, 1.5, -2)
def step_impl(context): context.a = Tuple(1,-2,3,-4)
def step_impl(context): assert -context.a == Tuple(-1,2,-3,4)
def step_impl(context): context.tg = Tuple(1, 2, 3, 4)
def step_impl(context): assert context.F * context.b == Tuple(18, 24, 33, 1)
def step_impl(context): context.b = Tuple(1, 2, 3, 1)