Try to fix mysterious "TypeError('only integer scalar arrays can be converted to a scalar index')

master
Per A Brodtkorb 8 years ago
parent 2c65591226
commit bb3848e31a

@ -249,7 +249,7 @@ class CovData1D(PlotData):
if method == 'fft': if method == 'fft':
nfft *= rate nfft *= rate
nf = nfft / 2 # number of frequencies nf = int(nfft // 2) # number of frequencies
acf = r_[acf, zeros(nfft - 2 * n + 2), acf[n - 2:0:-1]] acf = r_[acf, zeros(nfft - 2 * n + 2), acf[n - 2:0:-1]]
Rper = (fft(acf, nfft).real).clip(0) # periodogram Rper = (fft(acf, nfft).real).clip(0) # periodogram

@ -21,7 +21,7 @@ __all__ = ['dea3', 'clencurt', 'romberg',
'gaussq', 'richardson', 'quadgr', 'qdemo'] 'gaussq', 'richardson', 'quadgr', 'qdemo']
def clencurt(fun, a, b, n0=5, trace=False, args=()): def clencurt(fun, a, b, n0=5, trace=False):
''' '''
Numerical evaluation of an integral, Clenshaw-Curtis method. Numerical evaluation of an integral, Clenshaw-Curtis method.
@ -70,7 +70,7 @@ def clencurt(fun, a, b, n0=5, trace=False, args=()):
''' '''
# make sure n is even # make sure n is even
n = 2 * n0 n = 2 * int(n0)
a, b = np.atleast_1d(a, b) a, b = np.atleast_1d(a, b)
a_shape = a.shape a_shape = a.shape
af = a.ravel() af = a.ravel()
@ -110,16 +110,17 @@ def clencurt(fun, a, b, n0=5, trace=False, args=()):
# N+1 # N+1
# c(k) = (2/N) sum f''(n)*cos(pi*(2*k-2)*(n-1)/N), 1 <= k <= N/2+1. # c(k) = (2/N) sum f''(n)*cos(pi*(2*k-2)*(n-1)/N), 1 <= k <= N/2+1.
# n=1 # n=1
n0 = n // 2
fft = np.fft.fft fft = np.fft.fft
tmp = np.real(fft(f[:n, :], axis=0)) tmp = np.real(fft(f[:n, :], axis=0))
c = 2 / n * (tmp[0:n / 2 + 1, :] + np.cos(np.pi * s2) * f[n, :]) c = 2 / n * (tmp[0:n0 + 1, :] + np.cos(np.pi * s2) * f[n, :])
c[0, :] = c[0, :] / 2 c[0, :] = c[0, :] / 2
c[n / 2, :] = c[n / 2, :] / 2 c[n0, :] = c[n0, :] / 2
c = c[0:n / 2 + 1, :] / ((s2 - 1) * (s2 + 1)) c = c[0:n0 + 1, :] / ((s2 - 1) * (s2 + 1))
Q = (af - bf) * np.sum(c, axis=0) Q = (af - bf) * np.sum(c, axis=0)
abserr = (bf - af) * np.abs(c[n / 2, :]) abserr = (bf - af) * np.abs(c[n0, :])
if na > 1: if na > 1:
abserr = np.reshape(abserr, a_shape) abserr = np.reshape(abserr, a_shape)
@ -1291,7 +1292,7 @@ def qdemo(f, a, b, kmax=9, plot_error=False):
err_dic.setdefault(name, []).append(abs(q - true_val)) err_dic.setdefault(name, []).append(abs(q - true_val))
name = 'Clenshaw-Curtis' name = 'Clenshaw-Curtis'
q, _ec3 = clencurt(f, a, b, (n - 1) / 2) q, _ec3 = clencurt(f, a, b, (n - 1) // 2)
vals_dic.setdefault(name, []).append(q[0]) vals_dic.setdefault(name, []).append(q[0])
err_dic.setdefault(name, []).append(abs(q[0] - true_val)) err_dic.setdefault(name, []).append(abs(q[0] - true_val))

@ -1177,6 +1177,7 @@ def findrfc(tp, h=0.0, method='clib'):
if clib is not None and method == 'clib': if clib is not None and method == 'clib':
ind, ix = clib.findrfc(y, h) ind, ix = clib.findrfc(y, h)
ix = int(ix)
else: else:
ind = numba_misc.findrfc(y, h, method) ind = numba_misc.findrfc(y, h, method)
ix = len(ind) ix = len(ind)

@ -270,6 +270,7 @@ class LevelCrossings(PlotData):
nim1 = 0 nim1 = 0
x = [] x = []
for xk, ni in zip(lcx2.tolist(), lcf2.tolist()): for xk, ni in zip(lcx2.tolist(), lcf2.tolist()):
ni = int(ni)
x.append(ones(ni - nim1) * xk) x.append(ones(ni - nim1) * xk)
nim1 = ni nim1 = ni

Loading…
Cancel
Save