def __div__(self, other):
"""Element by element division."""
if isinstance(other, numpy.ndarray):
rv = SparseVector(max(self.n, other.shape[0]), {})
for k in self.values.keys():
rv[k] = self[k] / other[k]
return rv
elif isSparseVector(other):
rv = SparseVector(max(self.n, other.n), {})
for k in filter(self.values.has_key, other.values.keys()):
rv[k] = self[k] / other[k]
return rv
elif operator.isNumberType(other):
rv = SparseVector(self.n, {})
for k in self.values.keys():
rv[k] = self[k] / other
return rv
else:
raise TypeError("Cannot multiply with SparseVector")
评论列表
文章目录