how go overloading addition, subtraction, , multiplication operator can add, subtract, , multiply 2 vectors of different or identical sizes? example, if vectors different sizes must able add, subtract, or multiply 2 vectors according smallest vector size?
i've created function allows modify different vectors, i'm struggling overload operators , haven't clue on begin. paste code below. ideas?
def __add__(self, y): self.vector = [] j in range(len(self.vector)): self.vector.append(self.vector[j] + y.self.vector[j]) return vec[self.vector]
you define __add__
, __sub__
, , __mul__
methods class, that's how. each method takes 2 objects (the operands of +
/-
/*
) arguments , expected return result of computation.
Comments
Post a Comment