13
votes
Accepted
12
votes
generating tuples of ones and zeroes with a fixed number of ones
L[n_, m_] := Permutations@Array[Boole[# <= m] &, n]
L[3, 2]
(* {{1, 1, 0}, {1, 0, 1}, {0, 1, 1}} *)
11
votes
Accepted
How do I get a list of all possible sums in a list nested list?
Total[Tuples@rn, {2}]
should do.
For cases where a very large number of tuples would be generated,
...
11
votes
List of tuples without duplicates & repeated values
The accepted answer will quickly blow up with arguments of more than trivial sizes.
For example, with vals = {10, 20, 5, a, b, c} and ...
11
votes
Accepted
How to create all $1$'s vectors of length $n$ without using Tuples[]?
ArrayPad[IdentityMatrix[n], {{0, 1}, {0, 0}}, 1]
Or
PadRight[IdentityMatrix[n], {n + 1, n}, 1]
Or
...
7
votes
Tuples of elements from list excluding anything with repeated values
Just use Permutations:
Permutations[lst]
{{a, b, s, t}, {a, b, t, s}, {a, s, b, t}, {a, s, t, b}, {a, t, b, s}, {a, t,
...
7
votes
What is the identity for Tuples?
If {{1},{2},{3}} is fine, you can use Nothing:
...
7
votes
generating tuples of ones and zeroes with a fixed number of ones
With[{n = 5, k = 2},
ReplacePart[ConstantArray[0, n], Thread[# -> 1]] & /@
Subsets[Range[n], {k}]]
...
7
votes
Accepted
Faster searching for subsets with pairwise conditions
Might be faster to cull as you go. I compile the selection function (possibly it can be made faster). Also I set the history length to zero although that does not help too much because the ...
6
votes
Accepted
List of tuples without duplicates & repeated values
n = 2;
vals = {0, 1};
Tuples[vals, {n}] // DeleteDuplicatesBy[#, Sort] &
As the comment said
...
6
votes
Generating representatives of rotation classes of tuples of ones and zeros with a fixed number of ones
Not sure whether this works always correctly.
Say you want the lost of all $n$-tuples with $k$ 1 up to rotation. You can encode such a tuple by going through it in ...
6
votes
Faster searching for subsets with pairwise conditions
Correct me if I'm wrong, you're looking for 10,000 lists each with length 13, every element can be {1,2,3,4} and each list has at least 5 hamming distances from the ...
6
votes
Accepted
Working with tables: add new level of nested tables
We can use FrobeniusSolve to solve the equation
$$x_1+x_2+\cdots +x_n= m $$
Here n and m may ...
6
votes
5
votes
How do I get a list of all possible sums in a list nested list?
Few additional alternatives:
Distribute[foo @@ rn, List, foo, List, Plus]
Flatten @ Outer[Plus, ## & @@ rn]
Activate @ Tuples[Inactive[Plus] @@ rn]
5
votes
Accepted
How to list all possible 3-tuples with entries of the 3 tuples from 2 different sets?
{a, b} = {Range[4], Range[5, 8]};
triples = Tuples[{a, a, b}]
...
5
votes
Accepted
Sorted Tuples without Filtering
The function you are looking for is: Subsets.
E.g. for a list with n=5 elements and tuples with m=3 elements (note, you should not use capitalized variable names as those are used by the system):
<...
5
votes
How to create all $1$'s vectors of length $n$ without using Tuples[]?
You almost got the result you wanted, but somewhere you took a
wrong turn. The question states
The problem I have here, is that I want to concatenate this 1's vector with an identity matrix.
The ...
4
votes
What is the identity for Tuples?
You can use Inactive[Sequence][] as identity like this:
Tuples[{{Inactive[Sequence][]},{q}}]//Activate
{{q}}
4
votes
Accepted
Generating a list of tuples that meet certain criteria without running out of memory
Clear["Global`*"]
pool = Table[Range[3], 7] // Flatten;
Rather than produce all tuples, produce a tuple on demand
...
4
votes
Accepted
Selecting from a list returned by Tuples
There was an excelent answer with an illustration, but I would like to point out the specific mistakes:
Pure function in the second argmuent should end with &
<...
4
votes
Accepted
4
votes
What is the identity for Tuples?
Use TagSetDelayed to define a function that behaves as desired:
...
4
votes
generating tuples of ones and zeroes with a fixed number of ones
f[len_,wt_] := Table[
Boole[MemberQ[sub,i]],
{sub,Subsets[Range[len],{wt}]},
{i,len}
]
Try it online!
...
4
votes
generating tuples of ones and zeroes with a fixed number of ones
ClearAll[L2]
L2[n_, m_] := Permute[PadRight[ConstantArray[1, m], n], SymmetricGroup @ n]
L2[3, 2]
...
4
votes
Accepted
4
votes
4
votes
How to find repeating elements in the following grid?
If you know the lengths Length@grid1 == 6, Length@grid2 == 6, Length@grid3 == 5, then you ...
4
votes
Accepted
How to find repeating elements in the following grid?
If we know that tuples is constructed from ngrids input grids and if each grid has at least one non-repeating element, we can ...
4
votes
Accepted
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
tuples × 37list-manipulation × 20
combinatorics × 9
performance-tuning × 6
function-construction × 4
permutation × 4
table × 3
filtering × 3
conditional × 3
sorting × 3
functions × 2
memory × 2
graphics × 1
matrix × 1
graphs-and-networks × 1
probability-or-statistics × 1
linear-algebra × 1
replacement × 1
special-functions × 1
string-manipulation × 1
summation × 1
parametric-functions × 1
vector × 1
variable-definitions × 1
code-request × 1