Re: numpy permutations with replacement
On Apr 13, 7:13 am, Chris Rebert wrote: > On Mon, Apr 13, 2009 at 4:05 AM, [email protected] > > wrote: > > I am trying to generate all possible permutations of length three from > > elements of [0,1]. i.e in this scenario there are a total of 8 > > distinct permutations: > > > [0,0,0] > > [0,0,1] > > [0,1,0] > > . > > . > > . > > [1,1,1] > > > Does numpy define a function to achieve this ? > > No idea, but the Python standard library already has this covered with > itertools.permutations() > [http://docs.python.org/library/itertools.html]. > > Cheers, > Chris > > -- > I have a blog:http://blog.rebertia.com Thanks Chris, That looks promising, however I am still stuck at python 2.5 (I need numpy). And the 2.5 version does not look as nice as the 2.6 itertool. So, if there is a numpy method ... please let me know .. -- http://mail.python.org/mailman/listinfo/python-list
numpy permutations with replacement
I am trying to generate all possible permutations of length three from elements of [0,1]. i.e in this scenario there are a total of 8 distinct permutations: [0,0,0] [0,0,1] [0,1,0] . . . [1,1,1] Does numpy define a function to achieve this ? Thanks in advance -- http://mail.python.org/mailman/listinfo/python-list
Re: numpy permutations with replacement
On Apr 13, 1:17 pm, Mensanator wrote: > On Apr 13, 6:36 am, "[email protected]" wrote: > > > > > On Apr 13, 7:13 am, Chris Rebert wrote: > > > > On Mon, Apr 13, 2009 at 4:05 AM, [email protected] > > > > wrote: > > > > I am trying to generate all possible permutations of length three from > > > > elements of [0,1]. i.e in this scenario there are a total of 8 > > > > distinct permutations: > > > > > [0,0,0] > > > > [0,0,1] > > > > [0,1,0] > > > > . > > > > . > > > > . > > > > [1,1,1] > > > > > Does numpy define a function to achieve this ? > > > > No idea, but the Python standard library already has this covered with > > > itertools.permutations() > > > [http://docs.python.org/library/itertools.html]. > > > > Cheers, > > > Chris > > > > -- > > > I have a blog:http://blog.rebertia.com > > > Thanks Chris, > > > That looks promising, however I am still stuck at python 2.5 (I need > > numpy). And the 2.5 version does not look as nice as the 2.6 itertool. > > So, if there is a numpy method ... please let me know .. > > This isn't dependent on numpy or Python version: > > >>> e = [0,1] > >>> for i in e: > > for j in e: > for k in e: > print [i,j,k] > > [0, 0, 0] > [0, 0, 1] > [0, 1, 0] > [0, 1, 1] > [1, 0, 0] > [1, 0, 1] > [1, 1, 0] > [1, 1, 1] Much appreciated. This is exactly what was needed... -- http://mail.python.org/mailman/listinfo/python-list
Calendar yr-mnth-day data to day since data
Hi all, I have some calendar data in three arrays corresponding to yr, month, day that I would like to convert to day since data and be consistent with changes in leap year. I've included a sample of the data structures below. Any suggestions??? Thanks in advance yr mnthday daySince 19701 1 1 19701 15 15 19701 28 28 19702 1 32 19702 27 59 19703 1 19703 4 19703 29 ... ...... 20081 1 20081 8 20081 25 20082 1 -- http://mail.python.org/mailman/listinfo/python-list
Re: Calendar yr-mnth-day data to day since data
On Oct 3, 6:35 am, Piet van Oostrum wrote: > >>>>> "[email protected]" (sc) wrote: > >sc> Hi all, > >sc> I have some calendar data in three arrays corresponding to yr, month, > >sc> day that I would like to convert to day since data and be consistent > >sc> with changes in leap year. I've included a sample of the data > >sc> structures below. Any suggestions??? Thanks in advance > >sc> yr mnth day daySince > >sc> 1970 1 1 1 > >sc> 1970 1 15 15 > >sc> 1970 1 28 28 > >sc> 1970 2 1 > >sc> 32 > >sc> 1970 2 27 59 > >sc> 1970 3 1 > >sc> 1970 3 4 > >sc> 1970 3 29 > >sc> ... ... ... > >sc> 2008 1 1 > >sc> 2008 1 8 > >sc> 2008 1 25 > >sc> 2008 2 1 > > Days since what? It appears here to be since 1969-12-31, or since > 1970-1-1 but then starting with 1 instead of 0. > And your 59 is wrong if the others are deemed to be correct. > > Depending on what you want you have to add 1 to the following solution > > import datetime > startdate = datetime.date(1970, 1, 1) > enddate = datetime.date(1970,3,1) > timediff = enddate - startdate > print timediff.days > > result: 59 > -- > Piet van Oostrum > WWW:http://pietvanoostrum.com/ > PGP key: [8DAE142BE17999C4] Thanks ... This module does the trick nicely -- http://mail.python.org/mailman/listinfo/python-list
Identify runs in list
Hi all, I have a data structure in a list as in: [0 0 0 3 0 5 0 0 0 0 1 0 4 0 5 0 0 7 0 0 0 0 0 12 0 0 4] I would like to extract three list from this data: 1) runsOfZero: [3 4 5] 2) runsOfNonZero: [3 8 4] 3) SumOfRunsOfNonZero: [8 17 16] Any suggestions would be appreciated -- http://mail.python.org/mailman/listinfo/python-list
Re: Identify runs in list
On Oct 3, 10:36 pm, Chris Rebert wrote: > On Sat, Oct 3, 2009 at 7:21 PM, [email protected] > wrote: > > Hi all, > > > I have a data structure in a list as in: [0 0 0 3 0 5 0 0 0 0 1 0 4 0 > > 5 0 0 7 0 0 0 0 0 12 0 0 4] > > > I would like to extract three list from this data: > > > 1) runsOfZero: [3 4 5] > > 2) runsOfNonZero: [3 8 4] > > 3) SumOfRunsOfNonZero: [8 17 16] > > > Any suggestions would be appreciated > > Since this sounds like homework, I won't give actual code, but here's > a gameplan: > > 1. Split the list into sublists based on where the runs of zeros stop and > start. > 2. Categorize the sublists and place them into lists-of-lists based on > whether they have nonzero entries. To do the categorization, you'll > have to iterate over the original list and track how many previous 0s > you've seen consecutively. > 3. Use len() on the nonzero lists to get their length; puts the > results into a list (runsOfNonZero) > 4. Use sum() on the nonzero lists to get their sums, and put the > results into another list (SumOfRunsOfNonZero) > 5. Use len() on the all-zero lists to get their length and put the > results into a list (runsOfZero) > > Cheers, > Chris > --http://blog.rebertia.com Thanks Chris, Not homework but self learning. Also, forgot to mention that I only count runs greater than 3 (zeros). I will now look over your suggestions. Thanks again -- http://mail.python.org/mailman/listinfo/python-list
