最近在开发一个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)