Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #65278

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

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:: [': 0.04; 'sufficient': 0.05; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'rows': 0.09; 'subject:number': 0.09; 'suggest': 0.14; 'itertools': 0.16; 'other,': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:making': 0.16; 'subject:values': 0.16; 'wrote:': 0.18; 'subject:] ': 0.20; '>>>': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'tables': 0.26; 'this:': 0.26; 'header:X-Complaints-To:1': 0.27; 'array': 0.29; "i'm": 0.30; 'jean': 0.31; 'could': 0.34; 'subject:with': 0.35; 'really': 0.36; 'method': 0.36; 'too': 0.37; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'subject: ': 0.61; 'further': 0.61; 'kind': 0.63; 'such': 0.63; 'become': 0.64; 'here': 0.66
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: [newbie] making rows of table with discrete values for different number systems
Date Sun, 02 Feb 2014 19:10:32 +0100
Organization None
References <515e582f-ed17-4d4e-9872-f07f1fda6ed2@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p5084bc76.dip0.t-ipconnect.de
User-Agent KNode/4.7.3
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.6309.1391364617.18130.python-list@python.org> (permalink)
Lines 59
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1391364617 news.xs4all.nl 2965 [2001:888:2000:d::a6]:49598
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:65278

Show key headers only | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[newbie] making rows of table  with discrete values for different number systems Jean Dupont <jeandupont314@gmail.com> - 2014-02-02 09:44 -0800
  Re: [newbie] making rows of table  with discrete values for different number systems Roy Smith <roy@panix.com> - 2014-02-02 13:07 -0500
    Re: [newbie] making rows of table  with discrete values for different number systems Jean Dupont <jeandupont314@gmail.com> - 2014-02-03 07:06 -0800
  Re: [newbie] making rows of table with discrete values for different number systems Peter Otten <__peter__@web.de> - 2014-02-02 19:10 +0100
    Re: [newbie] making rows of table with discrete values for different number systems Jean Dupont <jeandupont314@gmail.com> - 2014-02-02 12:51 -0800
      Re: [newbie] making rows of table with discrete values for different number systems Asaf Las <roegltd@gmail.com> - 2014-02-02 17:56 -0800
        Re: [newbie] making rows of table with discrete values for different number systems Jean Dupont <jeandupont314@gmail.com> - 2014-02-03 07:05 -0800
          Re: [newbie] making rows of table with discrete values for different number systems Asaf Las <roegltd@gmail.com> - 2014-02-03 07:34 -0800
            Re: [newbie] making rows of table with discrete values for different number systems Jean Dupont <jeandupont314@gmail.com> - 2014-02-03 11:37 -0800
              Re: [newbie] making rows of table with discrete values for different number systems Asaf Las <roegltd@gmail.com> - 2014-02-03 11:50 -0800
                Re: [newbie] making rows of table with discrete values for different number systems Jean Dupont <jeandupont115@gmail.com> - 2014-02-04 01:18 -0800
              Re: [newbie] making rows of table with discrete values for different number systems Asaf Las <roegltd@gmail.com> - 2014-02-03 11:52 -0800
          Re: [newbie] making rows of table with discrete values for different number systems Terry Reedy <tjreedy@udel.edu> - 2014-02-03 16:50 -0500
            Re: [newbie] making rows of table with discrete values for different number systems Rustom Mody <rustompmody@gmail.com> - 2014-02-03 18:48 -0800
  Re: [newbie] making rows of table  with discrete values for different number systems Denis McMahon <denismfmcmahon@gmail.com> - 2014-02-04 00:11 +0000

csiph-web