[Tutor] Automatic generation of an "all possible combinations" array
Andy Cheesman
Andy.cheesman at bristol.ac.uk
Thu Jun 14 13:24:15 CEST 2007
Hi people
I am trying to generate an array of all possible combinations of 1, and
zeros (see example data) for a rather nice Kinetic mote Carlo program
which I am writing python. So far, I've been working out for
combinations for 4 or less species by hand as it is quick! but I am
looking to automate the process so I can compute combinations for large
numbers of possible species.
I could automate the generation of the array by the use of multiple
loops but that doesn't seem rather pythonic. I was wondering if anyone
had any sensible suggestions or pointers for efficient mechanisms for
the array.
Many Thanks
Andy
Example Data
3 species
array([[1, 1, 1],
[1, 1, 0],
[1, 0, 1],
[0, 1, 1],
[1, 0, 0],
[0, 1, 0],
[0, 0, 1],
[0, 0, 0]])
4 species
array([[1, 1, 1, 1],
[0, 1, 1, 1],
[1, 0, 1, 1],
[1, 1, 0, 1],
[1, 1, 1, 0],
[1, 1, 0, 0],
[1, 0, 1, 0],
[1, 0, 0, 1],
[0, 1, 1, 0],
[0, 1, 0, 1],
[0, 0, 1, 1],
[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1],
[0, 0, 0, 0]])
More information about the Tutor
mailing list