rem
stringlengths
0
322k
add
stringlengths
0
2.05M
context
stringlengths
8
228k
deltax = fontsize*points / 2.8 * DX / DY
deltax = fontsize*points / 2.6 * DX / DY
def legend(text,linetypes=None,lleft=None,color='black',tfont='helvetica',fontsize=14,nobox=0): """Construct and place a legend. Description: Build a legend and place it on the current plot with an interactive prompt. Inputs: text -- A list of strings which document the curves. linetypes -- If not given, then the t...
raise ValueError, "dense array does not have rank 1 or 2"
raise ValueError, "dense array must have rank 1 or 2"
def __init__(self, arg1, dims=None, nzmax=100, dtype='d', copy=False): spmatrix.__init__(self) if isdense(arg1): # Convert the dense array or matrix arg1 to CSC format if rank(arg1) == 2: s = arg1 if s.dtype.char not in 'fdFD': # Use a double array as the source (but leave it alone) s = s*1.0 if (rank(s) == 2): M, N = ...
else: raise ValueError, "dense array must have rank 1 or 2"
def __init__(self, arg1, dims=None, nzmax=100, dtype='d', copy=False): spmatrix.__init__(self) if isdense(arg1): # Convert the dense array or matrix arg1 to CSR format if rank(arg1) == 2: s = arg1 ocsc = csc_matrix(transpose(s)) self.colind = ocsc.rowind self.indptr = ocsc.indptr self.data = ocsc.data self.shape = (ocs...
def __getitem__(self, key):
def get(self, key, default=0.): """This overrides the dict.get method, providing type checking but otherwise equivalent functionality. """ try: i, j = key assert isinstance(i, int) and isinstance(j, int) except (AssertionError, TypeError, ValueError): raise IndexError, "index must be a pair of integers" try: assert not...
def __getitem__(self, key): if self._validate: # Sanity checks: key must be a pair of integers if not isinstance(key, tuple) or len(key) != 2: raise TypeError, "key must be a tuple of two integers" if type(key[0]) != int or type(key[1]) != int: raise TypeError, "key must be a tuple of two integers"
class _test_horiz_slicing(ScipyTestCase):
class _test_horiz_slicing:
def check_solve(self): """ Test whether the lu_solve command segfaults, as reported by Nils Wagner for a 64-bit machine, 02 March 2005 (EJS) """ n = 20 A = self.spmatrix((n,n), dtype=complex) x = numpy.rand(n) y = numpy.rand(n-1)+1j*numpy.rand(n-1) r = numpy.rand(n) for i in range(len(x)): A[i,i] = x[i] for i in range(...
class _test_vert_slicing(ScipyTestCase):
class _test_vert_slicing:
def check_get_horiz_slice(self): """Test for new slice functionality (EJS)""" B = asmatrix(arange(50.).reshape(5,10)) A = self.spmatrix(B) assert_array_equal(B[1,:], A[1,:].todense()) assert_array_equal(B[1,2:5], A[1,2:5].todense())
class _test_fancy_indexing(ScipyTestCase):
class _test_fancy_indexing:
def check_get_vert_slice(self): """Test for new slice functionality (EJS)""" B = asmatrix(arange(50.).reshape(5,10)) A = self.spmatrix(B) assert_array_equal(B[2:5,0], A[2:5,0].todense()) assert_array_equal(B[:,1], A[:,1].todense())
class test_csr(_test_cs, _test_horiz_slicing):
class test_csr(_test_cs, _test_horiz_slicing, ScipyTestCase):
def check_fancy_indexing(self): """Test for new indexing functionality""" B = ones((5,10), float) A = dok_matrix(B) # Write me! # Both slicing and fancy indexing: not yet supported # assert_array_equal(B[(1,2),:], A[(1,2),:].todense()) # assert_array_equal(B[(1,2,3),:], A[(1,2,3),:].todense())
class test_csc(_test_cs, _test_vert_slicing):
class test_csc(_test_cs, _test_vert_slicing, ScipyTestCase):
def check_empty(self): """Test manipulating empty matrices. Fails in SciPy SVN <= r1768 """ # This test should be made global (in _test_cs), but first we # need a uniform argument order / syntax for constructing an # empty sparse matrix. (coo_matrix is currently different). shape = (5, 5) for mytype in [float32, float6...
class test_dok(_test_cs):
class test_dok(_test_cs, ScipyTestCase):
def check_empty(self): """Test manipulating empty matrices. Fails in SciPy SVN <= r1768 """ # This test should be made global (in _test_cs), but first we # need a uniform argument order / syntax for constructing an # empty sparse matrix. (coo_matrix is currently different). shape = (5, 5) for mytype in [float32, float6...
class test_lil(_test_cs, _test_horiz_slicing):
class test_lil(_test_cs, _test_horiz_slicing, ScipyTestCase):
def check_set_slice(self): """Test for slice functionality (EJS)""" A = dok_matrix((5,10)) B = zeros((5,10), float) A[:,0] = 1 B[:,0] = 1 assert_array_equal(A.todense(), B) A[1,:] = 2 B[1,:] = 2 assert_array_equal(A.todense(), B) A[:,:] = 3 B[:,:] = 3 assert_array_equal(A.todense(), B) A[1:5, 3] = 4 B[1:5, 3] = 4 asser...
totalname = name apath, basename = os.path.split(name) name = name + ".ps"
if ignore == '.eps': totalname = name else: totalname = name + ignore apath, basename = os.path.split(totalname) name = totalname + ".ps"
def eps(name, epsi=0, pdf=0): """ Write the picture in the current graphics window to the Encapsulated PostScript file NAME+".eps" (i.e.- the suffix .eps is added to NAME). The last extension of name is stripped to avoid .eps.eps files If epsi is 1, this function requires the ps2epsi utility which comes with the proje...
res = os.system ("ps2epsi " + name)
res = os.system ("ps2epsi " + totalname)
def eps(name, epsi=0, pdf=0): """ Write the picture in the current graphics window to the Encapsulated PostScript file NAME+".eps" (i.e.- the suffix .eps is added to NAME). The last extension of name is stripped to avoid .eps.eps files If epsi is 1, this function requires the ps2epsi utility which comes with the proje...
os.remove(name)
os.remove(totalname)
def eps(name, epsi=0, pdf=0): """ Write the picture in the current graphics window to the Encapsulated PostScript file NAME+".eps" (i.e.- the suffix .eps is added to NAME). The last extension of name is stripped to avoid .eps.eps files If epsi is 1, this function requires the ps2epsi utility which comes with the proje...
0.51053920]),8)
0.51053919]),8)
def check_airy(self):
for n in range(4):
for n in range(2):
def check_airye(self):
assert_array_almost_equal(a,b1,5)
for n in range(2,4): b1[n] = b[n]*exp(-abs(real(2.0/3.0*0.01*sqrt(0.01)))) assert_array_almost_equal(a,b1,6)
def check_airye(self):
numstring = arange(0,2.2,.1)
numstring = arange(0,2.21,.1)
def check_arange(self): numstring = arange(0,2.2,.1) assert_equal(numstring,array([0.,0.1,0.2,0.3, 0.4,0.5,0.6,0.7, 0.8,0.9,1.,1.1, 1.2,1.3,1.4,1.5, 1.6,1.7,1.8,1.9, 2.,2.1])) numstringa = arange(3,4,.3) assert_array_equal(numstringa, array([3.,3.3,3.6,3.9])) numstringb = arange(3,27,3) assert_array_equal(numstringb,ar...
2.,2.1]))
2.,2.1,2.2]))
def check_arange(self): numstring = arange(0,2.2,.1) assert_equal(numstring,array([0.,0.1,0.2,0.3, 0.4,0.5,0.6,0.7, 0.8,0.9,1.,1.1, 1.2,1.3,1.4,1.5, 1.6,1.7,1.8,1.9, 2.,2.1])) numstringa = arange(3,4,.3) assert_array_equal(numstringa, array([3.,3.3,3.6,3.9])) numstringb = arange(3,27,3) assert_array_equal(numstringb,ar...
assert_array_equal(numstringb,array([3.,6.,9.,12., 15.,18.,21.,24.,27.]))
assert_array_equal(numstringb,array([3,6,9,12, 15,18,21,24]))
def check_arange(self): numstring = arange(0,2.2,.1) assert_equal(numstring,array([0.,0.1,0.2,0.3, 0.4,0.5,0.6,0.7, 0.8,0.9,1.,1.1, 1.2,1.3,1.4,1.5, 1.6,1.7,1.8,1.9, 2.,2.1])) numstringa = arange(3,4,.3) assert_array_equal(numstringa, array([3.,3.3,3.6,3.9])) numstringb = arange(3,27,3) assert_array_equal(numstringb,ar...
assert_array_equal(a,z)
assert_array_equal(a,x)
def check_array(self): x = array([1,2,3,4]) y = array([1,2,3,4]) z = x*y assert_array_equal(z,array([1,4,9,16])) a = arange(1,5,1) assert_array_equal(a,z)
suites.append( unittest.makeSuite(test_airy,'check_') ) suites.append( unittest.makeSuite(test_airye,'check_') ) suites.append( unittest.makeSuite(test_arange,'check_') )
def test_suite(level=1): suites = [] if level > 0:
suites.append( unittest.makeSuite(test_array,'check_') )
def test_suite(level=1): suites = [] if level > 0:
s = asarray(s) if s.typecode() not in 'fdFD': s = s*1.0
def __init__(self,s,ij=None,M=None,N=None,nzmax=100,typecode=Float,copy=0): spmatrix.__init__(self, 'csc') if isinstance(s,spmatrix): if isinstance(s, csc_matrix): # do nothing but copy information self.shape = s.shape if copy: self.data = s.data.copy() self.rowind = s.rowind.copy() self.indptr = s.indptr.copy() else: ...
a = spmatrix(arange(1,9),[0,1,1,2,2,3,3,4],[0,1,3,0,2,3,4,4])
a = csc_matrix(arange(1,9),ij=transpose([[0,1,1,2,2,3,3,4],[0,1,3,0,2,3,4,4]]))
def lu_factor(A, permc_spec=2, diag_pivot_thresh=1.0, drop_tol=0.0, relax=1, panel_size=10): M,N = A.shape if (M != N): raise ValueError, "Can only factor square matrices." csc = A.tocsc() gstrf = eval('_superlu.' + csc.ftype + 'gstrf') return gstrf(N,csc.nnz,csc.data,csc.rowind,csc.indptr,permc_spec, diag_pivot_thresh...
xplt.plot(x0,y0,type,x1,y1,type,hold=1)
plot(x0,y0,type,x1,y1,type,hold=1)
def axes(type='b|'): vals = gist.limits() x0 = [vals[0],vals[1]] y0 = [0,0] x1 = [0,0] y1 = [vals[2], vals[3]] xplt.plot(x0,y0,type,x1,y1,type,hold=1)
hist = scipy.histogram
from scipy.stats import histogram as hist
def histogram(data,nbins=80,range=None,ntype=0,bar=1,bwidth=0.8,bcolor=0): """Plot a histogram. ntype is the normalization type. Use ntype == 2 to compare with probability density function. """ h = SSH.histogram(data,nbins,range) if ntype == 1: h.normalize() elif ntype == 2: h.normalizeArea() if bar: barplot(h[:,0],h...
approx_grad = False,
approx_grad=0,
def fmin_l_bfgs_b(func, x0, fprime=None, args=(), approx_grad = False, bounds=None, m=10, factr=1e7, pgtol=1e-5, epsilon=1e-8, iprint=-1, maxfun=15000): """ Minimize a function func using the L-BFGS-B algorithm. Arguments: func -- function to minimize. Called as func(x, *args) x0 -- initial guess to minimum ...
x, f, d = fmin_l_bfgs_b(func, x0, approx_grad=True,
x, f, d = fmin_l_bfgs_b(func, x0, approx_grad=1,
def grad(x): g = NA.zeros(x.shape, NA.Float) t1 = x[1] - x[0]**2 g[0] = 2*(x[0]-1) - 16*x[0]*t1 for i in range(1, g.shape[0]-1): t2 = t1 t1 = x[i+1] - x[i]**2 g[i] = 8*t2 - 16*x[i]*t1 g[-1] = 8*t1 return g
"""Convolve two N-dimensional arrays using FFT. SEE convolve
"""Convolve two N-dimensional arrays using FFT. See convolve.
def fftconvolve(in1, in2, mode="full"): """Convolve two N-dimensional arrays using FFT. SEE convolve """ s1 = array(in1.shape) s2 = array(in2.shape) if (s1.dtype.char in ['D','F']) or (s2.dtype.char in ['D', 'F']): cmplx=1 else: cmplx=0 size = s1+s2-1 IN1 = fftn(in1,size) IN1 *= fftn(in2,size) ret = ifftn(IN1) del IN1 ...
if (Numeric.product(kernel.shape) > Numeric.product(volume.shape)):
if (product(kernel.shape) > product(volume.shape)):
def convolve(in1, in2, mode='full'): """Convolve two N-dimensional arrays. Description: Convolve in1 and in2 with output size determined by mode. Inputs: in1 -- an N-dimensional array. in2 -- an array with the same number of dimensions as in1. mode -- a flag indicating the size of the output 'valid' (0): The outpu...
domain = Numeric.ones(kernel_size) numels = Numeric.product(kernel_size)
domain = ones(kernel_size) numels = product(kernel_size)
def medfilt(volume,kernel_size=None): """Perform a median filter on an N-dimensional array. Description: Apply a median filter to the input array using a local window-size given by kernel_size. Inputs: in -- An N-dimensional input array. kernel_size -- A scalar or an N-length list giving the size of the median filt...
"""Perform a wiener filter on an N-dimensional array.
"""Perform a Wiener filter on an N-dimensional array.
def wiener(im,mysize=None,noise=None): """Perform a wiener filter on an N-dimensional array. Description: Apply a wiener filter to the N-dimensional array in. Inputs: in -- an N-dimensional array. kernel_size -- A scalar or an N-length list giving the size of the median filter window in each dimension. Elements of...
Apply a wiener filter to the N-dimensional array in.
Apply a Wiener filter to the N-dimensional array in.
def wiener(im,mysize=None,noise=None): """Perform a wiener filter on an N-dimensional array. Description: Apply a wiener filter to the N-dimensional array in. Inputs: in -- an N-dimensional array. kernel_size -- A scalar or an N-length list giving the size of the median filter window in each dimension. Elements of...
lMean = correlate(im,Numeric.ones(mysize),1) / Numeric.product(mysize)
lMean = correlate(im,ones(mysize),1) / product(mysize)
def wiener(im,mysize=None,noise=None): """Perform a wiener filter on an N-dimensional array. Description: Apply a wiener filter to the N-dimensional array in. Inputs: in -- an N-dimensional array. kernel_size -- A scalar or an N-length list giving the size of the median filter window in each dimension. Elements of...
lVar = correlate(im**2,Numeric.ones(mysize),1) / Numeric.product(mysize) - lMean**2
lVar = correlate(im**2,ones(mysize),1) / product(mysize) - lMean**2
def wiener(im,mysize=None,noise=None): """Perform a wiener filter on an N-dimensional array. Description: Apply a wiener filter to the N-dimensional array in. Inputs: in -- an N-dimensional array. kernel_size -- A scalar or an N-length list giving the size of the median filter window in each dimension. Elements of...
noise = mean(Numeric.ravel(lVar))
noise = mean(ravel(lVar))
def wiener(im,mysize=None,noise=None): """Perform a wiener filter on an N-dimensional array. Description: Apply a wiener filter to the N-dimensional array in. Inputs: in -- an N-dimensional array. kernel_size -- A scalar or an N-length list giving the size of the median filter window in each dimension. Elements of...
N = Numeric.size(a)-1 M = Numeric.size(b)-1
N = size(a)-1 M = size(b)-1
def lfiltic(b,a,y,x=None): """Given a linear filter (b,a) and initial conditions on the output y and the input x, return the inital conditions on the state vector zi which is used by lfilter to generate the output given the input. If M=len(b)-1 and N=len(a)-1. Then, the initial conditions are given in the vectors x a...
L = Numeric.size(x)
L = size(x)
def lfiltic(b,a,y,x=None): """Given a linear filter (b,a) and initial conditions on the output y and the input x, return the inital conditions on the state vector zi which is used by lfilter to generate the output given the input. If M=len(b)-1 and N=len(a)-1. Then, the initial conditions are given in the vectors x a...
L = Numeric.size(y)
L = size(y)
def lfiltic(b,a,y,x=None): """Given a linear filter (b,a) and initial conditions on the output y and the input x, return the inital conditions on the state vector zi which is used by lfilter to generate the output given the input. If M=len(b)-1 and N=len(a)-1. Then, the initial conditions are given in the vectors x a...
zi[m] = Numeric.sum(b[m+1:]*x[:M-m])
zi[m] = sum(b[m+1:]*x[:M-m])
def lfiltic(b,a,y,x=None): """Given a linear filter (b,a) and initial conditions on the output y and the input x, return the inital conditions on the state vector zi which is used by lfilter to generate the output given the input. If M=len(b)-1 and N=len(a)-1. Then, the initial conditions are given in the vectors x a...
zi[m] -= Numeric.sum(a[m+1:]*y[:N-m])
zi[m] -= sum(a[m+1:]*y[:N-m])
def lfiltic(b,a,y,x=None): """Given a linear filter (b,a) and initial conditions on the output y and the input x, return the inital conditions on the state vector zi which is used by lfilter to generate the output given the input. If M=len(b)-1 and N=len(a)-1. Then, the initial conditions are given in the vectors x a...
return Numeric.ones(M,Numeric.Float)
return ones(M, float)
def boxcar(M,sym=1): """The M-point boxcar window. """ return Numeric.ones(M,Numeric.Float)
return Numeric.array([])
return array([])
def triang(M,sym=1): """The M-point triangular window. """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M + 1 n = arange(1,int((M+1)/2)+1) if M % 2 == 0: w = (2*n-1.0)/M w = numpy.r_[w, w[::-1]] else: w = 2*n/(M+1.0) w = numpy.r_[w, w[-2::-1]] if not ...
return Numeric.ones(1,'d')
return ones(1,'d')
def triang(M,sym=1): """The M-point triangular window. """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M + 1 n = arange(1,int((M+1)/2)+1) if M % 2 == 0: w = (2*n-1.0)/M w = numpy.r_[w, w[::-1]] else: w = 2*n/(M+1.0) w = numpy.r_[w, w[-2::-1]] if not ...
w = numpy.r_[w, w[::-1]]
w = r_[w, w[::-1]]
def triang(M,sym=1): """The M-point triangular window. """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M + 1 n = arange(1,int((M+1)/2)+1) if M % 2 == 0: w = (2*n-1.0)/M w = numpy.r_[w, w[::-1]] else: w = 2*n/(M+1.0) w = numpy.r_[w, w[-2::-1]] if not ...
w = numpy.r_[w, w[-2::-1]]
w = r_[w, w[-2::-1]]
def triang(M,sym=1): """The M-point triangular window. """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M + 1 n = arange(1,int((M+1)/2)+1) if M % 2 == 0: w = (2*n-1.0)/M w = numpy.r_[w, w[::-1]] else: w = 2*n/(M+1.0) w = numpy.r_[w, w[-2::-1]] if not ...
return Numeric.array([])
return array([])
def parzen(M,sym=1): """The M-point Parzen window """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M+1 n = Numeric.arange(-(M-1)/2.0,(M-1)/2.0+0.5,1.0) na = extract(n < -(M-1)/4.0, n) nb = extract(abs(n) <= (M-1)/4.0, n) wa = 2*(1-abs(na)/(M/2.0))**3.0...
return Numeric.ones(1,'d')
return ones(1,'d')
def parzen(M,sym=1): """The M-point Parzen window """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M+1 n = Numeric.arange(-(M-1)/2.0,(M-1)/2.0+0.5,1.0) na = extract(n < -(M-1)/4.0, n) nb = extract(abs(n) <= (M-1)/4.0, n) wa = 2*(1-abs(na)/(M/2.0))**3.0...
n = Numeric.arange(-(M-1)/2.0,(M-1)/2.0+0.5,1.0)
n = arange(-(M-1)/2.0,(M-1)/2.0+0.5,1.0)
def parzen(M,sym=1): """The M-point Parzen window """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M+1 n = Numeric.arange(-(M-1)/2.0,(M-1)/2.0+0.5,1.0) na = extract(n < -(M-1)/4.0, n) nb = extract(abs(n) <= (M-1)/4.0, n) wa = 2*(1-abs(na)/(M/2.0))**3.0...
w = numpy.r_[wa,wb,wa[::-1]]
w = r_[wa,wb,wa[::-1]]
def parzen(M,sym=1): """The M-point Parzen window """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M+1 n = Numeric.arange(-(M-1)/2.0,(M-1)/2.0+0.5,1.0) na = extract(n < -(M-1)/4.0, n) nb = extract(abs(n) <= (M-1)/4.0, n) wa = 2*(1-abs(na)/(M/2.0))**3.0...
return Numeric.array([])
return array([])
def bohman(M,sym=1): """The M-point Bohman window """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M+1 fac = abs(linspace(-1,1,M)[1:-1]) w = (1 - fac)* cos(pi*fac) + 1.0/pi*sin(pi*fac) w = numpy.r_[0,w,0] if not sym and not odd: w = w[:-1] return w
return Numeric.ones(1,'d')
return ones(1,'d')
def bohman(M,sym=1): """The M-point Bohman window """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M+1 fac = abs(linspace(-1,1,M)[1:-1]) w = (1 - fac)* cos(pi*fac) + 1.0/pi*sin(pi*fac) w = numpy.r_[0,w,0] if not sym and not odd: w = w[:-1] return w
w = numpy.r_[0,w,0]
w = r_[0,w,0]
def bohman(M,sym=1): """The M-point Bohman window """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M+1 fac = abs(linspace(-1,1,M)[1:-1]) w = (1 - fac)* cos(pi*fac) + 1.0/pi*sin(pi*fac) w = numpy.r_[0,w,0] if not sym and not odd: w = w[:-1] return w
return Numeric.array([])
return array([])
def blackman(M,sym=1): """The M-point Blackman window. """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M+1 n = arange(0,M) w = 0.42-0.5*cos(2.0*pi*n/(M-1)) + 0.08*cos(4.0*pi*n/(M-1)) if not sym and not odd: w = w[:-1] return w
return Numeric.ones(1,'d')
return ones(1,'d')
def blackman(M,sym=1): """The M-point Blackman window. """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M+1 n = arange(0,M) w = 0.42-0.5*cos(2.0*pi*n/(M-1)) + 0.08*cos(4.0*pi*n/(M-1)) if not sym and not odd: w = w[:-1] return w
return Numeric.array([])
return array([])
def nuttall(M,sym=1): """A minimum 4-term Blackman-Harris window according to Nuttall. """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M+1 a = [0.3635819, 0.4891775, 0.1365995, 0.0106411] n = arange(0,M) fac = n*2*pi/(M-1.0) w = a[0] - a[1]*cos(fac) +...
return Numeric.ones(1,'d')
return ones(1,'d')
def nuttall(M,sym=1): """A minimum 4-term Blackman-Harris window according to Nuttall. """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M+1 a = [0.3635819, 0.4891775, 0.1365995, 0.0106411] n = arange(0,M) fac = n*2*pi/(M-1.0) w = a[0] - a[1]*cos(fac) +...
return Numeric.array([])
return array([])
def blackmanharris(M,sym=1): """The M-point minimum 4-term Blackman-Harris window. """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M+1 a = [0.35875, 0.48829, 0.14128, 0.01168]; n = arange(0,M) fac = n*2*pi/(M-1.0) w = a[0] - a[1]*cos(fac) + a[2]*cos(2...
return Numeric.ones(1,'d')
return ones(1,'d')
def blackmanharris(M,sym=1): """The M-point minimum 4-term Blackman-Harris window. """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M+1 a = [0.35875, 0.48829, 0.14128, 0.01168]; n = arange(0,M) fac = n*2*pi/(M-1.0) w = a[0] - a[1]*cos(fac) + a[2]*cos(2...
return Numeric.array([])
return array([])
def bartlett(M,sym=1): """The M-point Bartlett window. """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M+1 n = arange(0,M) w = where(Numeric.less_equal(n,(M-1)/2.0),2.0*n/(M-1),2.0-2.0*n/(M-1)) if not sym and not odd: w = w[:-1] return w
return Numeric.ones(1,'d')
return ones(1,'d')
def bartlett(M,sym=1): """The M-point Bartlett window. """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M+1 n = arange(0,M) w = where(Numeric.less_equal(n,(M-1)/2.0),2.0*n/(M-1),2.0-2.0*n/(M-1)) if not sym and not odd: w = w[:-1] return w
w = where(Numeric.less_equal(n,(M-1)/2.0),2.0*n/(M-1),2.0-2.0*n/(M-1))
w = where(less_equal(n,(M-1)/2.0),2.0*n/(M-1),2.0-2.0*n/(M-1))
def bartlett(M,sym=1): """The M-point Bartlett window. """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M+1 n = arange(0,M) w = where(Numeric.less_equal(n,(M-1)/2.0),2.0*n/(M-1),2.0-2.0*n/(M-1)) if not sym and not odd: w = w[:-1] return w
return Numeric.array([])
return array([])
def hanning(M,sym=1): """The M-point Hanning window. """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M+1 n = arange(0,M) w = 0.5-0.5*cos(2.0*pi*n/(M-1)) if not sym and not odd: w = w[:-1] return w
return Numeric.ones(1,'d')
return ones(1,'d')
def hanning(M,sym=1): """The M-point Hanning window. """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M+1 n = arange(0,M) w = 0.5-0.5*cos(2.0*pi*n/(M-1)) if not sym and not odd: w = w[:-1] return w
return Numeric.array([])
return array([])
def barthann(M,sym=1): """Return the M-point modified Bartlett-Hann window. """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M+1 n = arange(0,M) fac = abs(n/(M-1.0)-0.5) w = 0.62 - 0.48*fac + 0.38*cos(2*pi*fac) if not sym and not odd: w = w[:-1] return...
return Numeric.ones(1,'d')
return ones(1,'d')
def barthann(M,sym=1): """Return the M-point modified Bartlett-Hann window. """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M+1 n = arange(0,M) fac = abs(n/(M-1.0)-0.5) w = 0.62 - 0.48*fac + 0.38*cos(2*pi*fac) if not sym and not odd: w = w[:-1] return...
return Numeric.array([])
return array([])
def hamming(M,sym=1): """The M-point Hamming window. """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M+1 n = arange(0,M) w = 0.54-0.46*cos(2.0*pi*n/(M-1)) if not sym and not odd: w = w[:-1] return w
return Numeric.ones(1,'d')
return ones(1,'d')
def hamming(M,sym=1): """The M-point Hamming window. """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M+1 n = arange(0,M) w = 0.54-0.46*cos(2.0*pi*n/(M-1)) if not sym and not odd: w = w[:-1] return w
return Numeric.array([])
return array([])
def kaiser(M,beta,sym=1): """Returns a Kaiser window of length M with shape parameter beta. """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M+1 n = arange(0,M) alpha = (M-1)/2.0 w = special.i0(beta * sqrt(1-((n-alpha)/alpha)**2.0))/special.i0(beta) if...
return Numeric.ones(1,'d')
return ones(1,'d')
def kaiser(M,beta,sym=1): """Returns a Kaiser window of length M with shape parameter beta. """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M+1 n = arange(0,M) alpha = (M-1)/2.0 w = special.i0(beta * sqrt(1-((n-alpha)/alpha)**2.0))/special.i0(beta) if...
return Numeric.array([])
return array([])
def gaussian(M,std,sym=1): """Returns a Gaussian window of length M with standard-deviation std. """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M + 1 n = arange(0,M)-(M-1.0)/2.0 sig2 = 2*std*std w = exp(-n**2 / sig2) if not sym and not odd: w = w[:-1...
return Numeric.ones(1,'d')
return ones(1,'d')
def gaussian(M,std,sym=1): """Returns a Gaussian window of length M with standard-deviation std. """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M + 1 n = arange(0,M)-(M-1.0)/2.0 sig2 = 2*std*std w = exp(-n**2 / sig2) if not sym and not odd: w = w[:-1...
return Numeric.array([])
return array([])
def general_gaussian(M,p,sig,sym=1): """Returns a window with a generalized Gaussian shape. exp(-0.5*(x/sig)**(2*p)) half power point is at (2*log(2)))**(1/(2*p))*sig """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M+1 n = arange(0,M)-(M-1.0)/2.0 w ...
return Numeric.ones(1,'d')
return ones(1,'d')
def general_gaussian(M,p,sig,sym=1): """Returns a window with a generalized Gaussian shape. exp(-0.5*(x/sig)**(2*p)) half power point is at (2*log(2)))**(1/(2*p))*sig """ if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M+1 n = arange(0,M)-(M-1.0)/2.0 w ...
return Numeric.array([])
return array([])
def slepian(M,width,sym=1): if (M*width > 27.38): raise ValueError, "Cannot reliably obtain slepian sequences for"\ " M*width > 27.38." if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M+1 twoF = width/2.0 alpha = (M-1)/2.0 m = arange(0,M)-alpha n = m[:,N...
return Numeric.ones(1,'d')
return ones(1,'d')
def slepian(M,width,sym=1): if (M*width > 27.38): raise ValueError, "Cannot reliably obtain slepian sequences for"\ " M*width > 27.38." if M < 1: return Numeric.array([]) if M == 1: return Numeric.ones(1,'d') odd = M % 2 if not sym and not odd: M = M+1 twoF = width/2.0 alpha = (M-1)/2.0 m = arange(0,M)-alpha n = m[:,N...
if numpy.iscomplexobj(x):
if iscomplexobj(x):
def hilbert(x, N=None): """Return the hilbert transform of x of length N. """ x = asarray(x) if N is None: N = len(x) if N <=0: raise ValueError, "N must be positive." if numpy.iscomplexobj(x): print "Warning: imaginary part of x ignored." x = numpy.real(x) Xf = fft(x,N,axis=0) h = Numeric.zeros(N) if N % 2 == 0: h[0] ...
x = numpy.real(x)
x = real(x)
def hilbert(x, N=None): """Return the hilbert transform of x of length N. """ x = asarray(x) if N is None: N = len(x) if N <=0: raise ValueError, "N must be positive." if numpy.iscomplexobj(x): print "Warning: imaginary part of x ignored." x = numpy.real(x) Xf = fft(x,N,axis=0) h = Numeric.zeros(N) if N % 2 == 0: h[0] ...
h = Numeric.zeros(N)
h = zeros(N)
def hilbert(x, N=None): """Return the hilbert transform of x of length N. """ x = asarray(x) if N is None: N = len(x) if N <=0: raise ValueError, "N must be positive." if numpy.iscomplexobj(x): print "Warning: imaginary part of x ignored." x = numpy.real(x) Xf = fft(x,N,axis=0) h = Numeric.zeros(N) if N % 2 == 0: h[0] ...
h = h[:,Numeric.NewAxis]
h = h[:, NewAxis]
def hilbert(x, N=None): """Return the hilbert transform of x of length N. """ x = asarray(x) if N is None: N = len(x) if N <=0: raise ValueError, "N must be positive." if numpy.iscomplexobj(x): print "Warning: imaginary part of x ignored." x = numpy.real(x) Xf = fft(x,N,axis=0) h = Numeric.zeros(N) if N % 2 == 0: h[0] ...
if numpy.iscomplexobj(x):
if iscomplexobj(x):
def hilbert2(x,N=None): """Return the '2-D' hilbert transform of x of length N. """ x = asarray(x) x = asarray(x) if N is None: N = x.shape if len(N) < 2: if N <=0: raise ValueError, "N must be positive." N = (N,N) if numpy.iscomplexobj(x): print "Warning: imaginary part of x ignored." x = numpy.real(x) print N Xf = ff...
x = numpy.real(x)
x = real(x)
def hilbert2(x,N=None): """Return the '2-D' hilbert transform of x of length N. """ x = asarray(x) x = asarray(x) if N is None: N = x.shape if len(N) < 2: if N <=0: raise ValueError, "N must be positive." N = (N,N) if numpy.iscomplexobj(x): print "Warning: imaginary part of x ignored." x = numpy.real(x) print N Xf = ff...
h1 = Numeric.zeros(N[0],'d') h2 = Numeric.zeros(N[1],'d')
h1 = zeros(N[0],'d') h2 = zeros(N[1],'d')
def hilbert2(x,N=None): """Return the '2-D' hilbert transform of x of length N. """ x = asarray(x) x = asarray(x) if N is None: N = x.shape if len(N) < 2: if N <=0: raise ValueError, "N must be positive." N = (N,N) if numpy.iscomplexobj(x): print "Warning: imaginary part of x ignored." x = numpy.real(x) print N Xf = ff...
h = h[:,Numeric.NewAxis]
h = h[:, NewAxis]
def hilbert2(x,N=None): """Return the '2-D' hilbert transform of x of length N. """ x = asarray(x) x = asarray(x) if N is None: N = x.shape if len(N) < 2: if N <=0: raise ValueError, "N must be positive." N = (N,N) if numpy.iscomplexobj(x): print "Warning: imaginary part of x ignored." x = numpy.real(x) print N Xf = ff...
if numpy.iscomplexobj(p): indx = Numeric.argsort(abs(p))
if iscomplexobj(p): indx = argsort(abs(p))
def cmplx_sort(p): "sort roots based on magnitude." p = asarray(p) if numpy.iscomplexobj(p): indx = Numeric.argsort(abs(p)) else: indx = Numeric.argsort(p) return Numeric.take(p,indx), indx
indx = Numeric.argsort(p) return Numeric.take(p,indx), indx
indx = argsort(p) return take(p,indx), indx
def cmplx_sort(p): "sort roots based on magnitude." p = asarray(p) if numpy.iscomplexobj(p): indx = Numeric.argsort(abs(p)) else: indx = Numeric.argsort(p) return Numeric.take(p,indx), indx
from numpy import real_if_close, atleast_1d
def unique_roots(p,tol=1e-3,rtype='min'): """Determine the unique roots and their multiplicities in two lists Inputs: p -- The list of roots tol --- The tolerance for two roots to be considered equal. rtype --- How to determine the returned root from the close ones: 'max': pick the maximum 'min': pick the minimum 'a...
r = Numeric.take(r,indx)
r = take(r,indx)
def invres(r,p,k,tol=1e-3,rtype='avg'): """Compute b(s) and a(s) from partial fraction expansion: r,p,k If M = len(b) and N = len(a) b(s) b[0] x**(M-1) + b[1] x**(M-2) + ... + b[M-1] H(s) = ------ = ---------------------------------------------- a(s) a[0] x**(N-1) + a[1] x**(N-2) + ... + a[N-1] r[0] r[...
while Numeric.allclose(b[0], 0, rtol=1e-14) and (b.shape[-1] > 1):
while allclose(b[0], 0, rtol=1e-14) and (b.shape[-1] > 1):
def invres(r,p,k,tol=1e-3,rtype='avg'): """Compute b(s) and a(s) from partial fraction expansion: r,p,k If M = len(b) and N = len(a) b(s) b[0] x**(M-1) + b[1] x**(M-2) + ... + b[M-1] H(s) = ------ = ---------------------------------------------- a(s) a[0] x**(N-1) + a[1] x**(N-2) + ... + a[N-1] r[0] r[...
r = Numeric.take(r,indx)
r = take(r,indx)
def invresz(r,p,k,tol=1e-3,rtype='avg'): """Compute b(z) and a(z) from partial fraction expansion: r,p,k If M = len(b) and N = len(a) b(z) b[0] + b[1] z**(-1) + ... + b[M-1] z**(-M+1) H(z) = ------ = ---------------------------------------------- a(z) a[0] + a[1] z**(-1) + ... + a[N-1] z**(-N+1) r[0] ...
N = int(Numeric.minimum(num,Nx)) Y = Numeric.zeros(newshape,'D')
N = int(numpy.minimum(num,Nx)) Y = zeros(newshape,'D')
def resample(x,num,t=None,axis=0,window=None): """Resample to num samples using Fourier method along the given axis. The resampled signal starts at the same value of x but is sampled with a spacing of len(x) / num * (spacing of x). Because a Fourier method is used, the signal is assumed periodic. Window controls a F...
from numpy import expand_dims, unique, prod, sort, zeros, ones, \ reshape, r_, any, c_, transpose, take, dot import scipy.linalg as linalg
def resample(x,num,t=None,axis=0,window=None): """Resample to num samples using Fourier method along the given axis. The resampled signal starts at the same value of x but is sampled with a spacing of len(x) / num * (spacing of x). Because a Fourier method is used, the signal is assumed periodic. Window controls a F...
if mode == 'F': image = Image.fromstring(mode,shape,data.astype('f').tostring()) elif mode == 'I':
if mode == 'I':
def toimage(arr,high=255,low=0,cmin=None,cmax=None,pal=None, mode=None,channel_axis=None): """Takes a Numeric array and returns a PIL image. The mode of the PIL image depends on the array shape, the pal keyword, and the mode keyword. For 2-D arrays, if pal is a valid (N,3) byte-array giving the RGB values (from 0 to ...
if isinstance(other, dok_matrix):
if isinstance(other, spmatrix):
def __mul__(self, other): if isinstance(other, dok_matrix): return self.matmat(other) other = asarray(other) if rank(other) > 0: return self.matvec(other) res = dok_matrix() for key in self.keys(): res[key] = other * self[key] return res
current_row = ikey0 row_ptr[ikey0] = k
N = ikey1-current_col row_ptr[current_row+1:ikey0+1] = [k]*N current_row = ikey0
def tocsr(self): # Return Compressed Sparse Row format arrays for this matrix keys = self.keys() keys.sort() nnz = len(keys) data = [0]*nnz colind = [0]*nnz row_ptr = [0]*(self.shape[0]+1) current_row = -1 k = 0 for key in keys: ikey0 = int(key[0]) ikey1 = int(key[1]) if ikey0 != current_row: current_row = ikey0 row_pt...
data = [None]*nnz colind = [None]*nnz col_ptr = [None]*(self.shape[1]+1) current_col = -1
data = [0]*nnz rowind = [0]*nnz col_ptr = [0]*(self.shape[1]+1) current_col = 0
def tocsc(self): # Return Compressed Sparse Column format arrays for this matrix keys = self.keys() keys.sort(csc_cmp) nnz = len(keys) data = [None]*nnz colind = [None]*nnz col_ptr = [None]*(self.shape[1]+1) current_col = -1 k = 0 for key in keys: ikey0 = int(key[0]) ikey1 = int(key[1]) if ikey1 != current_col: current...
col_ptr[ikey1] = k
def tocsc(self): # Return Compressed Sparse Column format arrays for this matrix keys = self.keys() keys.sort(csc_cmp) nnz = len(keys) data = [None]*nnz colind = [None]*nnz col_ptr = [None]*(self.shape[1]+1) current_col = -1 k = 0 for key in keys: ikey0 = int(key[0]) ikey1 = int(key[1]) if ikey1 != current_col: current...
colind[k] = ikey0
rowind[k] = ikey0
def tocsc(self): # Return Compressed Sparse Column format arrays for this matrix keys = self.keys() keys.sort(csc_cmp) nnz = len(keys) data = [None]*nnz colind = [None]*nnz col_ptr = [None]*(self.shape[1]+1) current_col = -1 k = 0 for key in keys: ikey0 = int(key[0]) ikey1 = int(key[1]) if ikey1 != current_col: current...
colind = array(colind)
rowind = array(rowind)
def tocsc(self): # Return Compressed Sparse Column format arrays for this matrix keys = self.keys() keys.sort(csc_cmp) nnz = len(keys) data = [None]*nnz colind = [None]*nnz col_ptr = [None]*(self.shape[1]+1) current_col = -1 k = 0 for key in keys: ikey0 = int(key[0]) ikey1 = int(key[1]) if ikey1 != current_col: current...