I want to create a List of binary arrays, which are combination of two inverse binary Tuples
, like this:
tup3={{0, 0, 0, 1, 1, 1}, {0, 0, 1, 1, 1, 0}, {0, 1, 0, 1, 0, 1},
{0, 1, 1, 1, 0, 0}, {1, 0, 0, 0, 1, 1}, {1, 0, 1, 0, 1, 0},
{1, 1, 0, 0, 0, 1}, {1, 1, 1, 0, 0, 0}}
I was able to create it using Riffle
and then reshaping the array (for arbitrary nn
):
nn=3;
ArrayReshape[Riffle[Tuples[{0, 1}, nn], Tuples[{1, 0}, nn]], {2^nn, 2*nn}]
However it looks too complicated to me, and I believe that Mathematica would provide a simpler method. Also I wonder whether there is a faster method.
Edit: Let me compare all methods up to now in terms of speed:
Edit2 (01.01.2017, 23.00):
For nn=23
:
- SimonWoods2: 3.38987sec
- kglr5: 3.3****
- kglr4: 3.5703sec
- NicoDean: 6.63795sec
- SimonWoods1: 7.68363sec
- kglr3: 8.21169sec
- BobHanlon: 10.9597sec
- kglr2: 22.067sec
- kglr1: 22.9503sec
The methods of Simon Woods and kglr are significantly faster than my solution, and at the moment faster than any other proposals. And the top-3 for nn=27
:
- kglr (
PadRight
): 63.13 +/- 2.86 sec (individual: 61.2264, 60.551, 63.6354, 67.7876, 62.4526) - kglr (
ArrayPad
): 63.18 +/- 1.75 sec (individual: 63.54, 60.27, 63.57, 65.03, 63.50) - Simon Woods (
ArrayFlatten
): 62.89 +/- 3.00 sec (individual: 58.5406, 63.3664, 64.3787, 65.2684)
(very similar and within the errors)