From: Nadav H. <na...@vi...> - 2004-03-24 06:28:49
|
The nd_image module in numarray has a spline intrpolation function=20 (spline_filter1d). I've tried it, and it is OK. Nadav. -----Original Message----- From: Ray Schumacher [mailto:ra...@bl...] Sent: Tue 23-Mar-04 03:11 To: num...@li... Cc:=09 Subject: [Numpy-discussion] interpolating arrays (?) Howdy, I'd like to resize an array (1-dimensional) a of length n into an array = of=20 n+x, and interpolate the values as necessary. x might be+/-200, len(a) is usually ~500 I tried it in pure Python but it's not quite right yet. (rubberBand, = below) Someone out there must have done this... and linear interpolation for=20 values is probably sufficient (instead of bi-cubic or some such) Cheers, Ray =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D startSlice =3D 10000 endOfSlice =3D=20 10000+int(round(self.samplesPerRotation)) = #self.samplesPerRotation=3D661 ## self.dataArray is about len=3D200,000 of Int for delta in range(-2,3): ## interpolate the different slices to the original length ## 0 should return the same array, this is a test newArray =3D self.rubberBand( = self.dataArray[startSlice:endOfSlice+delta], round(self.samplesPerRotation)) print len(self.dataArray[startSlice:endOfSlice+delta]),=20 len(newArray), ## show the result print delta, = Numeric.sum(self.dataArray[startSlice:endOfSlice]=20 - newArray) def rubberBand(self, data, desiredLength): """ alias/interpolate the data so that it is adjusted to the=20 desired array length""" currentLength =3D float(len(data)) ## positive if the new array is to be longer difference =3D desiredLength - currentLength #print difference, desiredLength, currentLength ## set up the desired length array newData =3D Numeric.zeros(desiredLength, Numeric.Float) ## accounts for binary rounding errors smallNum =3D 2**-14 for index in range(desiredLength): ## find the ratio of the current index to the desired = length ratio =3D index / float(desiredLength) ## find the same (float) position in the old data currIndex =3D int(ratio * currentLength) ## find the decimal part decimalPart =3D (ratio * currentLength) - currIndex print index, currIndex, decimalPart, if(decimalPart>smallNum): ## interpolate newData[index] =3D ((1 - decimalPart) * data[currIndex] = +=20 decimalPart * data[currIndex+1]) print data[currIndex], data[currIndex+1], = newData[index] else: newData[index] =3D data[currIndex] print 'else',data[currIndex], newData[index] return newData ------------------------------------------------------- This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=3D1470&alloc_id=3D3638&op=3Dcli= ck _______________________________________________ Numpy-discussion mailing list Num...@li... https://lists.sourceforge.net/lists/listinfo/numpy-discussion |