sparse_vector_class.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:NLP.py 作者: PythonOptimizers 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号