Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 125
4 votes

What is the identity for Tuples?

Use TagSetDelayed to define a function that behaves as desired: ClearAll[iDentity] iDentity /: {iDentity[___], a : {__}} := iDentity[a] iDentity /: Tuples[iDentity[a_]] := a Tuples[{iDentity[], {q}} … }] := a altTuples[x_] := Tuples[x] altTuples[{{x, y}, {1, 2}}] {{x, 1}, {x, 2}, {y, 1}, {y, 2}} altTuples[{tuplesIdentity, {1, 2}}] {1, 2} altTuples[{{}, {1, 2}}] {1, 2} …
kglr's user avatar
  • 401k
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}] {{1, 1, 5}, {1, 1, 6}, {1, 1, 7}, {1, 1, 8}, {1, 2, 5}, {1, 2, 6}, {1, 2, 7}, {1, 2, 8}, {1, 3, 5}, {1, 3, 6}, {1, 3, 7}, {1, 3, 8}, { …
kglr's user avatar
  • 401k
2 votes

Making figure from list of tuples

arrow = Arrow[{{0, -1/2}, {0, 1/2}}]; (1) Use Tuples[{-1, 1}, n] (instead of Tuples[{0, 1}, n]) to obtain a list of directions, (2) Partition that list to get a matrix of desired dimensions, (3) Use … that matrix to Scale and Translate the graphics primitive arrow: ClearAll[arrowTable] arrowTable[n_, k_, len_, as_, opts : OptionsPattern[] ] := Module[{m = Partition[Join @@ Tuples[{-1, 1}, n], k …
kglr's user avatar
  • 401k
1 vote
Accepted

Referencing data in sets of sets

You can use ReplaceAll: rules = {{0, 1, 1} -> setA, {1, 1, 0} -> setB}; data /. rules {setA, setA, setB, setA, setB} Alternatively, define a function that evaluates to setA for {0,1,1} and to set …
kglr's user avatar
  • 401k
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] …
kglr's user avatar
  • 401k
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 get the duplicates and their counts in each of the grids using extractDuplicates … = Map[l |-> Select[GreaterThan[1]] @ Normalize[#, Min] & @ Counts[#[[All,l]]]] @ Range @ #2 &; ngrids = 3; extractDuplicates[tuples, ngrids] {<|0.2 -> 2|>, <||>, <|0.35 -> 2|>} We can get …
kglr's user avatar
  • 401k
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] {{1, 1, 0}, {1, 0, 1}, {0, 1, 1}} L2[4, 2] {{1, 1, 0, 0}, {1, 0, 1, 0}, {1, 0, 0, 1}, {0, 1, …
kglr's user avatar
  • 401k
2 votes
Accepted

Joining each element of second tuples to the end of each element of the first tuples

tup4a = Join @@@ Tuples[{tup1, tup3}]; tup4a // Short {{0,-1,-1,0,-1,-1,d,0,0},{0,-1,-1,0,-1,-1,d,0,1},<<2912>>, {1,1,1,1,1,1,d,-1,1},{1,1,1,1,1,1,d,-1,-1}} tup4b = Distribute[{tup1, tup3}, List … , List, List, Join]; tup4a == tup4b True "to get that directly from tup1 and tup2": tup4c = Join @@@ Tuples[{tup1, {{d}}, tup2}]; tup4a == tup4c True …
kglr's user avatar
  • 401k
3 votes

generating tuples of ones and zeroes with a fixed number of ones

ClearAll[f0] f0 = Module[{ss = MapIndexed[Thread[{#2[[1]], #}] &, Subsets[Range@#, {#2}]]}, SparseArray[Join @@ ss -> 1, {Length@ss, #}]] &; Examples: f0[3, 2] f0[3, 2] // Normal {{1, 1, 0} …
kglr's user avatar
  • 401k