numba_array_impl.py 文件源码

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

项目:numba-examples 作者: numba 项目源码 文件源码
def distances_numba_array(cluster):
    # Original: diff = cluster[:, np.newaxis, :] - cluster[np.newaxis, :, :]
    # Since np.newaxis is not supported, we use reshape to do this
    diff = (cluster.reshape(cluster.shape[0], 1, cluster.shape[1]) -
            cluster.reshape(1, cluster.shape[0], cluster.shape[1]))
    mat = (diff * diff)
    # Original: mat = mat.sum(-1)
    # Since axis argument is not supported, we write the loop out
    out = np.empty(mat.shape[:2], dtype=mat.dtype)
    for i in np.ndindex(out.shape):
        out[i] = mat[i].sum()

    return np.sqrt(out)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号