Apr-03-2020, 05:58 PM
Hi guys I'm having a problem with an assignment in my class we are now on using fullmatrix and sparce and I get this error in my code :
class Vector(object): def __init__(self, data): self.data = data self.rows = len(data) def __mul__(self, other): assert self.rows == other.rows return sum([vi * vj for vi, vj in zip(self.data, other.data)]) def __rmul__(self, a): data = [a * d for d in self.data] return Vector(data) def __add__(self, other): assert self.rows == other.rows return Vector([i + j for (i, j) in zip(self.data, other.data)]) def __sub__(self, other): assert self.rows == other.rows return Vector([i - j for (i, j) in zip(self.data, other.data)]) def norm(self): return math.sqrt(self * self) def __str__(self): return '{0}'.format(self.data)
Error: File "C:\Users\illar\Desktop\05.py", line 116, in <listcomp>
data = [a * d for d in self.data]
TypeError: can't multiply sequence by non-int of type 'float'