这是一个嵌套循环,其中内部索引取决于外部索引,具有以下参数:
f = rand(1,70299)
nech=24*30*24
N=length(f);
xh=(1:nech)/24;
Run Code Online (Sandbox Code Playgroud)
在 MATLAB 中:
sf2(1:nech)=0.;
sf2vel(1:nech)=0.;
count(1:nech)=0.;
for i=1:nech
for j=1:N-i-1
sf2(i)=sf2(i)+(f(j+i)-f(j))^2;
count(i)=count(i)+1;
end
sf2(i)=sf2(i)/count(i);
end
Run Code Online (Sandbox Code Playgroud)
在Python中:
def structFunPython(f,N,nech):
sf2 = np.zeros(N)
count = np.zeros(N)
for i in range(nech):
indN = np.arange(1,N-i-1)
for j in indN:
sf2[i] += np.power((f[i+j]-f[j]),2)
count[i] += 1
sf2[i] = sf2[i]/count[i]
return sf2
Run Code Online (Sandbox Code Playgroud)
与赛通:
import cython
cimport numpy as np
import numpy as np
def structFun(np.ndarray f,N,nech):
cdef np.ndarray sf2 = np.zeros(N), count = np.zeros(N),
for i in range(nech):
indN …Run Code Online (Sandbox Code Playgroud)