Tag Info

New answers tagged

2

This is very fast : n=20; A={{4, 5, 9, 19}, {3, 7, 8, 11}, {3, 7, 9, 18}, {1, 3, 10, 17}, {5, 6, 10, 19}, {3, 7, 13, 20}, {3, 8, 15, 19}, {2, 7, 15, 20}, {11, 14, 15, 17}, {1, 3, 12, 20}}; f = Compile[{{n, _Integer}, {Ax, _Integer, 1}}, Module[{tab}, tab = Array[0 &, {n}]; (tab[[#]] = 1) & /@ Ax; tab ], RuntimeAttributes ...


0

I propose: Array[Boole@MemberQ[a[[#1]], #2] &, {w, n}] ...Short, but slow. Well, after that first feeble attempt, I present this faster version... Module[{m = ConstantArray[0, {w, n}]}, Set[m[[##]], 1] & @@@ (Join @@ Inner[List, Range[w], a, List]); m];


5

This s/b quite quick: IntegerDigits[Total@Transpose@(2^Subtract[n, a]), 2, n] N.b. - I changed A to a - it's almost always a bad idea to use uppercase initials for you own symbols... And this is wicked fast: Module[{ca = ConstantArray[0, n w]}, ca[[Flatten[a + Range[0, w n - 1, n]]]] = 1; Partition[ca, n]] Of the answers so far, for n = 20; k = 4; ...


2

Untested: SparseArray[Thread[Flatten[Inner[List, Range[w], A, List], 1] -> 1], {w, n}]


1

This is likely primarily due to array unpacking. See here: What is a Mathematica packed array? list1 takes only ByteCount[list1] (* 200000144 *) space when packed, but this increases to ByteCount@Developer`FromPackedArray[list1] (* 600000080 *) when unpacking. It's the same for list2, so the total rises to 1.2 GB. Make a rule list out of these ...



Top 50 recent answers are included