小编sam*_*lfe的帖子

寻求 Numpy 中计算量大的数学函数的优化

最近在开发一个Python脚本,实现一个特定的数学函数,如下图所示

在此输入图像描述

其中指数化是周期性的并且1 <= j <= n. 功能比较复杂,受到之前一个问题的启发。该代码的主要目的是评估大型数组x(大小为 5000 或更大)的数学函数。以下是该函数在 Python 中的当前实现:

import numpy as np
import sys, os

def compute_y(x, L, v):
    n = len(x)
    y = np.zeros(n)

    for k in range(L+1):
        # Generate the indices for the window around each j, with periodic wrapping
        indices = np.arange(-k, k+1)

        # Compute the weights
        weights_1 = k - np.abs(indices)
        weights_2 = k + 1 - np.abs(indices)
        weights_d = np.ones(2*k+1)

        # For each j, take the …
Run Code Online (Sandbox Code Playgroud)

python optimization performance numpy vectorization

2
推荐指数
1
解决办法
165
查看次数

标签 统计

numpy ×1

optimization ×1

performance ×1

python ×1

vectorization ×1