nonlinear_expansion.py 文件源码

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

项目:cuicuilco 作者: AlbertoEsc 项目源码 文件源码
def products_2(x, func, k=0):
    """Computes func(xi, xj) over all possible indices i and j constrained to j >= i+k.

    func is an arbitrary function, and k >= 0 is an integer
    """

    x_height, x_width = x.shape

    mask = numpy.triu(numpy.ones((x_width, x_width)), k) > 0.5

    z1 = x.reshape(x_height, x_width, 1)
    z2 = x.reshape(x_height, 1, x_width)
    yexp = func(z1, z2)  # twice computation, but performance gain due to lack of loops

    out = yexp[:, mask]
    return out
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号