Binary numbers

sampe99 at my-deja.com sampe99 at my-deja.com
Wed Feb 7 11:47:28 EST 2001


In article <mailman.981486160.19141.python-list at python.org>,
  Kenneth Loafman <ken at lt.com> wrote:
> This is my second post on this subject.  Mail to this user bounces.
> Could be a troll, but since I'd already answered, here's what I said
> (important to conserve electrons, don't you know)...
>
> sampe99 at my-deja.com wrote:
> >
> > Does anyone know an easy way to get a list of binary numbers within
a
> > certain range in python? E.g for
> > n=1 [0],[1]
> > n=2 [0,0],[0,1],[1,0],[1,1]
> > n=3 [0,0,0],[0,0,1] a.s.o
> >
> > I need this for n<=18...
>
> With n=18, you're asking for
> [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
> [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
> [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1],
> ...
> [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
>
> n=18 would be a huge list of lists, (2^18) * 18 in size.
>
> Assuming 4-byte integers, that would be (262144 * 18 * 4) = 18,874,368
> which is 18MB in data alone.  Throw in the python list overhead and it
> would probably occupy 25-30MB.  Of course, printing it out would be
> impractical (useless?).
>
> Any practical use for such a list?
>
> ...Ken
>
>

First, thanks to you all that presented excellent solutions to my
problem.

And to Ken. The basic problem is to make a transition probability
matrix (over one year) apply to a smaller time frame (like a week). To
do this I take the n:th root of the matrix which produces n different
solutions for each eigenvalue. I found python returns only one answer
to x**(1/n) and I therefor need to try all possible combinations of
positive and negative eigenvalues to find the correct solution. It
would also be preferred to try the complex roots too...

Do you have a better solution to this main problem I would be happy :)

Thanks again,

Sam


Sent via Deja.com
http://www.deja.com/



More information about the Python-list mailing list