def __rpow__(self, other):
"""Use each element of sparse vector as power of base."""
if not isSparseVector(self):
raise TypeError("Argument must be a SparseVector")
if not isinstance(other, types.IntType) and \
not isinstance(other, types.LongType) and \
not isinstance(other, types.FloatType):
raise TypeError("Power must be numeric")
rv = SparseVector(self.n, {})
for k in self.values.keys():
rv[k] = math.pow(other, self[k])
return rv
评论列表
文章目录