min max of a list
If this is the list. values = [ 0, 72, 0, 4, 9, 2, 0, 0, 42, 26, 0, 282, 23, 0, 101, 0, 0, 0, 0, 0] as we can see there are peaks in the list.that is 0,72,0 is a group(triangle) with peak 72.then 0, 4, 9, 2, 0, 0 with peak 9 and 0, 42, 26, 0 with 42 and so on... what I want is the left and right bound index of each bin(triangle).The list could as big as possible.So some heurestic algorithm which could first find max in the list and look for local maxima and minima and group its adjcent bounds.Then find next max and group the bins and so on. so that we can get [[0,2],[2,7],[7,10],[10,13]] ( indexes of the bounds in the values list). so first group [0,2] correspond to 0,72,0 in the values list and so on... Hope I am clear. -- http://mail.python.org/mailman/listinfo/python-list
Re: min max of a list
Thanks for that. My version of python does'nt find "groupby". I am using python 2.3.2. Is there a way I could do it with out using groupby -- http://mail.python.org/mailman/listinfo/python-list
Re: min max of a list
what if we do something like this. Assume the values list is the content of a histogram. Then we see that values = [ 0, 72, 0, 4, 9, 2, 0, 0, 42, 26, 0, 282, 23, 0, 101, 0, 0, 0, 0, 0] 1 is repeated 72 times, 3 -> 4 times and so on. That is the index would be the value repeated as many times as in the list. Now If we find the max and look for the adjcent index. FOr example take 282 : Index of 282 --> 11 now check for value of index 10 and 12 .If value(10) < value(9) then there is a dip as value(9) and value(11) are greater than value(10). that could be the lower bound of that range. then if value(11) and value(13) for value(12). if value(11)< value(10) there is a dip. SO the bounds of [10,12] -> [0,282,23] rather than [10, 13] values: [0, 282, 23, 0] ( in your case). How would this work. Is there someway I could do this faster. -- http://mail.python.org/mailman/listinfo/python-list
Re: min max of a list
Hi Steve! I am not sure if I was clear with my previous post .Ok let me rephrase it . Assume the values list is the content of a histogram. Then we see that values = [ 0, 72, 2, 4, 9, 2, 0, 0, 42, 26, 0, 282, 23, 0, 101, 0, 0, 0, 0, 0] 1 is repeated 72 times, 3 -> 4 times and so on. That is the index would be the value repeated as many times as in the list. Now If we find the max and look for the adjcent index. That is if we plot the above list as a histogram. We will have crests and troughs ie peaks and dips. if we find two dips then the region between the two dips could be a range like [0, 72, 2] .So here we are not looking for a zero. But if we find dips then we consider the regions between it as a bin and group it. | /\ | /\ / \ /\ | / \/\/ \ |/_ ||-|---| 123 so pictorially. In the above plot. If y axis is the list above. then we need to bin it this way. If I use you previous approach using the groupby then all these three regions will be considered as one. Hope I am clear this time. -- http://mail.python.org/mailman/listinfo/python-list
Re: min max of a list
Hi Kent, Thanks for that. But We are considering [..., 0, 101, 0, 0, 0, 0, 0] -> [13,18] .In fact if you look at the list, the histogram ends at 15 that is [0,101,0] --> [13,15]. Dont you think so. -- http://mail.python.org/mailman/listinfo/python-list
Re: min max of a list
I get a syntax error in : py> [(min((abs(p - v), v) for v in valleys + [0] if v < p)[1], ... p, ... min((abs(p - v), v) for v in valleys if v > p)[1]) ... for p in peaks] -- http://mail.python.org/mailman/listinfo/python-list
Re: min max of a list
oh yes its the same case. even [0,4,9,2,0] as a set [2,6] and may be not [2,7]. Its not that you are wrong its jus that I was not clear. Sorry about that. -- http://mail.python.org/mailman/listinfo/python-list
Resize an Image without PIL
Hi I would like to know how to resize an Image without using python Imaging library. -- http://mail.python.org/mailman/listinfo/python-list
Improve the performance of a loop
What is the fastest way to code this particular block of code below.. I used numeric for this currently and I thought it should be really fast.. But, for large sets of data (bx and vbox) it takes a long time and I would like to improve. vbox = array(m) (size: 1000x1000 approx) for b in bx: vbox[ b[1], b[0]:b[2] ] = 0 vbox[ b[3], b[0]:b[2] ] = 0 vbox[ b[1]:b[3], b[0] ] = 0 vbox[ b[1]:b[3], b[2] ] = 0 and vbox is a 2D array where bx is of form [( int,int,int,int),() ] -- http://mail.python.org/mailman/listinfo/python-list
Re: Improve the performance of a loop
Actually slicing the way you suggested improved it to some extent. I did profile on this and I observed that it reduced the number of calls for __get_item__ and improved the timing to some extent. Which was useful to some extent. Thanks again. -- http://mail.python.org/mailman/listinfo/python-list
scipy for python 2.4
Did anyone try to install Scipy package on python2.4 linux version. I see only python2.3 version of scipy released. When I try to install I get an dependency warning saying scipy cannot find python2.3. Can someone point me to python2.4 version of scipy and help me install. -- http://mail.python.org/mailman/listinfo/python-list
Re: scipy for python 2.4
I tried to compile it from source. But it dint work.It was looking for python2.3 .But I want to install it on pyrthon 2.4 PLatform you mean I am using RedHat 9.0. is that what you were referring? can you point me to the source you are referring. I used the sourse from this link... http://www.scipy.org/download/ -- http://mail.python.org/mailman/listinfo/python-list
convert a string to tuple
how do I convert b is a string b = '(1,2,3,4)' to b = (1,2,3,4) -- http://mail.python.org/mailman/listinfo/python-list
time consuming loops over lists
X-No-Archive: yes Can some one help me improve this block of code...this jus converts the list of data into tokens based on the range it falls into...but it takes a long time.Can someone tell me what can i change to improve it... def Tkz(tk,data): no_of_bins = 10 tkns = [] dmax = max(data)+1 dmin = min(data) rng = ceil(abs((dmax - dmin)/(no_of_bins*1.0))) rngs = zeros(no_of_bins+1) for i in xrange(no_of_bins+1): rngs[i] = dmin + (rng*i) for i in xrange(len(data)): for j in xrange(len(rngs)-1): if data[i] in xrange(rngs[j],rngs[j+1]): tkns.append( str(tk)+str(j) ) return tkns -- http://mail.python.org/mailman/listinfo/python-list
Re: time consuming loops over lists
wow i dint know that a single statement like that would make such a difference. Thanks you very much. that really improves the performance -- http://mail.python.org/mailman/listinfo/python-list
