Re: [newbie] making rows of table with discrete values for different number systems

2014-02-04 Thread Jean Dupont
Op maandag 3 februari 2014 20:50:04 UTC+1 schreef Asaf Las:
> On Monday, February 3, 2014 9:37:36 PM UTC+2, Jean Dupont wrote:
> > Op maandag 3 februari 2014 16:34:18 UTC+1 schreef Asaf Las:
> > 
> > Of course you don't have to, but I'm curious and learn well by examples
> > :-(
>
> Hi Jean 
>
> Don't get me wrong i did not mean to be rude (was joking) - i 
> think if you will do it yourself that will be very good for 
> you - you can learn a lot from that as i did not very long time ago. 
> My apologies for inconvenience.
no hard feelings, anyway I am programming it myself using normal functions, 
when I have finished it I'll post it, then maybe you can do it with 
lamba-notation, it could be interesting to compare execution times for the two 
approaches

kind regards,
jean

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] making rows of table with discrete values for different number systems

2014-02-03 Thread Rustom Mody
On Tuesday, February 4, 2014 3:20:06 AM UTC+5:30, Terry Reedy wrote:
> name = lambda xxx is poor style because it produces a function object 
> lacking a proper name. Reusing the function name as a local is also 
> confusing. The above is equivalent to

> def m(k, n): return 1 if k & n else 0

Yeah... Well... Except that I'd put it the other way: the second --
shadowing names -- is MUCH worse than naked lambdas. Unless you're
entering an obfuscated python contest :D
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] making rows of table with discrete values for different number systems

2014-02-03 Thread Denis McMahon
On Sun, 02 Feb 2014 09:44:05 -0800, Jean Dupont wrote:

> I'm looking for an efficient method to produce rows of tables like this:
> 
> for base 2 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 .
> .
> .
> 1 1 1 1
> 
> for base 3 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 2 0 0 0 0 1 0 0 0 0 0 1 1 0
> 0 0 0 1 2 .
> .
> 2 2 2 2 2 2
> 
> As you can see the rows are always twice the size of the base I _don't_
> need to have all rows available together in one array which would become
> too large for higher value number bases. It's sufficient to produce one
> row after the other, as I will do further data manipulation on such a
> row immediately.
> 
> If someone here could suggest best practices to perform this kind of
> operations,I'd really appreciate it very much
> 
> kind regards and thanks in advance jean

s=3
p=s*2

def b(n,x):
s=[]
while n:
s.append(str(n%x))
n=n/x
if s==[]:
return "0"
return ''.join(s[::-1])

for i in range(s**p):
r=("{:0"+str(p)+"d}").format(int(b(i,s)))
if len(r)==p:
print [int(r[a])for a in range(len(r))]

change s to 2 or 4 etc

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] making rows of table with discrete values for different number systems

2014-02-03 Thread Terry Reedy

On 2/3/2014 10:05 AM, Jean Dupont wrote:

Op maandag 3 februari 2014 02:56:43 UTC+1 schreef Asaf Las:

On Sunday, February 2, 2014 10:51:15 PM UTC+2, Jean Dupont wrote:

Op zondag 2 februari 2014 19:10:32 UTC+1 schreef Peter Otten:

I'm looking for an efficient method to produce rows of tables like this:
jean

you can also try to make below universal for all needed bases:
m = lambda m, n: 1 if m & n else 0


name = lambda xxx is poor style because it produces a function object 
lacking a proper name. Reusing the function name as a local is also 
confusing. The above is equivalent to


def m(k, n): return 1 if k & n else 0


k = [[ m(x,8) , m(x, 4), m(x, 2), m(x, 1)] for x in range(10)]
print (k)

Dear Asaf,
I'm not at ease with lamba-notation, could you show me how to modify your
example for the base 3 case? I guess then it will be much clearer to me

thanks in advance
jean




--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] making rows of table with discrete values for different number systems

2014-02-03 Thread Asaf Las
On Monday, February 3, 2014 9:37:36 PM UTC+2, Jean Dupont wrote:
> Op maandag 3 februari 2014 16:34:18 UTC+1 schreef Asaf Las:
> 
> Of course you don't have to, but I'm curious and learn well by examples
> 
> :-(

And making this design generic is really a good example indeed.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] making rows of table with discrete values for different number systems

2014-02-03 Thread Asaf Las
On Monday, February 3, 2014 9:37:36 PM UTC+2, Jean Dupont wrote:
> Op maandag 3 februari 2014 16:34:18 UTC+1 schreef Asaf Las:
> 
> Of course you don't have to, but I'm curious and learn well by examples
> :-(

Hi Jean 

Don't get me wrong i did not mean to be rude (was joking) - i 
think if you will do it yourself that will be very good for 
you - you can learn a lot from that as i did not very long time ago. 
My apologies for inconvenience.

/Asaf

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] making rows of table with discrete values for different number systems

2014-02-03 Thread Jean Dupont
Op maandag 3 februari 2014 16:34:18 UTC+1 schreef Asaf Las:
> On Monday, February 3, 2014 5:05:40 PM UTC+2, Jean Dupont wrote:
> > Op maandag 3 februari 2014 02:56:43 UTC+1 schreef Asaf Las:
> > 
> > > On Sunday, February 2, 2014 10:51:15 PM UTC+2, Jean Dupont wrote:
> > > > Op zondag 2 februari 2014 19:10:32 UTC+1 schreef Peter Otten:
> > > > I'm looking for an efficient method to produce rows of tables like 
> > > > this: 
> > > > jean
> > 
> > > you can also try to make below universal for all needed bases: 
> > > m = lambda m, n: 1 if m & n else 0
> > > k = [[ m(x,8) , m(x, 4), m(x, 2), m(x, 1)] for x in range(10)]
> > 
> > > print (k)
> > 
> > Dear Asaf,
> > I'm not at ease with lamba-notation, could you show me how to modify your
> > example for the base 3 case? I guess then it will be much clearer to me
> > thanks in advance
> > 
> > jean
>
> I don't have to - use normal functions instead :-)
Of course you don't have to, but I'm curious and learn well by examples

:-(
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] making rows of table with discrete values for different number systems

2014-02-03 Thread Asaf Las
On Monday, February 3, 2014 5:05:40 PM UTC+2, Jean Dupont wrote:
> Op maandag 3 februari 2014 02:56:43 UTC+1 schreef Asaf Las:
> 
> > On Sunday, February 2, 2014 10:51:15 PM UTC+2, Jean Dupont wrote:
> > > Op zondag 2 februari 2014 19:10:32 UTC+1 schreef Peter Otten:
> > > I'm looking for an efficient method to produce rows of tables like this: 
> > > jean
> 
> > you can also try to make below universal for all needed bases: 
> > m = lambda m, n: 1 if m & n else 0
> > k = [[ m(x,8) , m(x, 4), m(x, 2), m(x, 1)] for x in range(10)]
> 
> > print (k)
> 
> Dear Asaf,
> I'm not at ease with lamba-notation, could you show me how to modify your
> example for the base 3 case? I guess then it will be much clearer to me
> thanks in advance
> 
> jean

I don't have to - use normal functions instead :-)

/Asaf
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] making rows of table with discrete values for different number systems

2014-02-03 Thread Jean Dupont
Op zondag 2 februari 2014 19:07:38 UTC+1 schreef Roy Smith:
> In article <515e582f-ed17-4d4e-9872-f07f1fda6...@googlegroups.com>,
>  Jean Dupont  wrote:
>
> > I'm looking for an efficient method to produce rows of tables like this:
> > 
> > for base 2
> > 0 0 0 0
> > 0 0 0 1
> > 0 0 1 0
> > 0 0 1 1
> > 0 1 0 0
> > .
> > .
> > .
> > 1 1 1 1
> > 
> > for base 3
> > 0 0 0 0 0 0
> > 0 0 0 0 0 1
> > 0 0 0 0 0 2
> > 0 0 0 0 1 0
> > 0 0 0 0 1 1
> > 0 0 0 0 1 2
> > .
> > .
> > 2 2 2 2 2 2
>
> This sounds like a homework problem :-)
>
> > As you can see the rows are always twice the size of the base
>
> Why?
>
> > I _don't_ need to have all rows available together in one array which would 
> > become too large for higher value number bases. It's sufficient to produce
> > one row after the other, as I will do further data manipulation on such a 
> > row
> > immediately.
>
> What I get out of that is that you don't want to just print them, you 
> want to have some function which returns all the generated rows in 
> order.  The way to do that is with the yield statement.  Take a look at 
> https://wiki.python.org/moin/Generators for some discussion on how that 
> works.  Actually, http://stackoverflow.com/questions/231767/
> looks like an even better discussion.
>
> Does that help you any?

Thanks, I'll try to figure out what yield does

kind regards,
jean
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] making rows of table with discrete values for different number systems

2014-02-03 Thread Jean Dupont
Op maandag 3 februari 2014 02:56:43 UTC+1 schreef Asaf Las:
> On Sunday, February 2, 2014 10:51:15 PM UTC+2, Jean Dupont wrote:
> > Op zondag 2 februari 2014 19:10:32 UTC+1 schreef Peter Otten:
> > 
> > I'm looking for an efficient method to produce rows of tables like this: 
> > jean
> you can also try to make below universal for all needed bases: 
> m = lambda m, n: 1 if m & n else 0
> k = [[ m(x,8) , m(x, 4), m(x, 2), m(x, 1)] for x in range(10)]
> print (k)
Dear Asaf,
I'm not at ease with lamba-notation, could you show me how to modify your
example for the base 3 case? I guess then it will be much clearer to me

thanks in advance
jean
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] making rows of table with discrete values for different number systems

2014-02-02 Thread Asaf Las
On Sunday, February 2, 2014 10:51:15 PM UTC+2, Jean Dupont wrote:
> Op zondag 2 februari 2014 19:10:32 UTC+1 schreef Peter Otten:
> 
> I'm looking for an efficient method to produce rows of tables like this: 
> jean

you can also try to make below universal for all needed bases: 

m = lambda m, n: 1 if m & n else 0
k = [[ m(x,8) , m(x, 4), m(x, 2), m(x, 1)] for x in range(10)]
print (k)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] making rows of table with discrete values for different number systems

2014-02-02 Thread Jean Dupont
Op zondag 2 februari 2014 19:10:32 UTC+1 schreef Peter Otten:
> Jean Dupont wrote:
>
> > I'm looking for an efficient method to produce rows of tables like this:
> > 
> > for base 2
> > 0 0 0 0
> > 0 0 0 1
> > 0 0 1 0
> > 0 0 1 1
> > 0 1 0 0
> > .
> > .
> > .
> > 1 1 1 1
> > 
> > for base 3
> > 0 0 0 0 0 0
> > 0 0 0 0 0 1
> > 0 0 0 0 0 2
> > 0 0 0 0 1 0
> > 0 0 0 0 1 1
> > 0 0 0 0 1 2
> > .
> > .
> > 2 2 2 2 2 2
> > 
> > As you can see the rows are always twice the size of the base
> > I _don't_ need to have all rows available together in one array which
> > would become too large for higher value number bases. It's sufficient to
> > produce one row after the other, as I will do further data manipulation on
> > such a row immediately.
> > 
> > If someone here could suggest best practices to perform this kind of
> > operations,I'd really appreciate it very much
>
> Have a look at itertools.product(): 
>
> >>> import itertools
> >>> for row in itertools.product(range(2), repeat=4):
> ... print(*row)
> ... 
> 0 0 0 0
> 0 0 0 1
> 0 0 1 0
> 0 0 1 1
> 0 1 0 0
> 0 1 0 1
> 0 1 1 0
> 0 1 1 1
> 1 0 0 0
> 1 0 0 1
> 1 0 1 0
> 1 0 1 1
> 1 1 0 0
> 1 1 0 1
> 1 1 1 0
> 1 1 1 1

Thanks for the suggestion I'm going to look into it further

kind regards,
jean
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] making rows of table with discrete values for different number systems

2014-02-02 Thread Peter Otten
Jean Dupont wrote:

> I'm looking for an efficient method to produce rows of tables like this:
> 
> for base 2
> 0 0 0 0
> 0 0 0 1
> 0 0 1 0
> 0 0 1 1
> 0 1 0 0
> .
> .
> .
> 1 1 1 1
> 
> for base 3
> 0 0 0 0 0 0
> 0 0 0 0 0 1
> 0 0 0 0 0 2
> 0 0 0 0 1 0
> 0 0 0 0 1 1
> 0 0 0 0 1 2
> .
> .
> 2 2 2 2 2 2
> 
> As you can see the rows are always twice the size of the base
> I _don't_ need to have all rows available together in one array which
> would become too large for higher value number bases. It's sufficient to
> produce one row after the other, as I will do further data manipulation on
> such a row immediately.
> 
> If someone here could suggest best practices to perform this kind of
> operations,I'd really appreciate it very much

Have a look at itertools.product(): 

>>> import itertools
>>> for row in itertools.product(range(2), repeat=4):
... print(*row)
... 
0 0 0 0
0 0 0 1
0 0 1 0
0 0 1 1
0 1 0 0
0 1 0 1
0 1 1 0
0 1 1 1
1 0 0 0
1 0 0 1
1 0 1 0
1 0 1 1
1 1 0 0
1 1 0 1
1 1 1 0
1 1 1 1


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] making rows of table with discrete values for different number systems

2014-02-02 Thread Roy Smith
In article <515e582f-ed17-4d4e-9872-f07f1fda6...@googlegroups.com>,
 Jean Dupont  wrote:

> I'm looking for an efficient method to produce rows of tables like this:
> 
> for base 2
> 0 0 0 0
> 0 0 0 1
> 0 0 1 0
> 0 0 1 1
> 0 1 0 0
> .
> .
> .
> 1 1 1 1
> 
> for base 3
> 0 0 0 0 0 0
> 0 0 0 0 0 1
> 0 0 0 0 0 2
> 0 0 0 0 1 0
> 0 0 0 0 1 1
> 0 0 0 0 1 2
> .
> .
> 2 2 2 2 2 2

This sounds like a homework problem :-)

> As you can see the rows are always twice the size of the base

Why?

> I _don't_ need to have all rows available together in one array which would 
> become too large for higher value number bases. It's sufficient to produce
> one row after the other, as I will do further data manipulation on such a row
> immediately.

What I get out of that is that you don't want to just print them, you 
want to have some function which returns all the generated rows in 
order.  The way to do that is with the yield statement.  Take a look at 
https://wiki.python.org/moin/Generators for some discussion on how that 
works.  Actually, http://stackoverflow.com/questions/231767/
looks like an even better discussion.

Does that help you any?
-- 
https://mail.python.org/mailman/listinfo/python-list