#### Convenience Functions to be moved to kerneltools ####
from statsmodels.compat.python import range
import numpy as np
[docs]def forrt(X,m=None):
"""
RFFT with order like Munro (1976) FORTT routine.
"""
if m is None:
m = len(X)
y = np.fft.rfft(X,m)/m
return np.r_[y.real,y[1:-1].imag]
[docs]def revrt(X,m=None):
"""
Inverse of forrt. Equivalent to Munro (1976) REVRT routine.
"""
if m is None:
m = len(X)
y = X[:m/2+1] + np.r_[0,X[m/2+1:],0]*1j
return np.fft.irfft(y)*m
[docs]def counts(x,v):
"""
Counts the number of elements of x that fall within the grid points v
Notes
-----
Using np.digitize and np.bincount
"""
idx = np.digitize(x,v)
try: # numpy 1.6
return np.bincount(idx, minlength=len(v))
except:
bc = np.bincount(idx)
return np.r_[bc,np.zeros(len(v)-len(bc))]
[docs]def kdesum(x,axis=0):
return np.asarray([np.sum(x[i] - x, axis) for i in range(len(x))])