Counting elements of multidimensional list according to patternsSpecifying string patterns in DeleteCasesGenerating a list of cubefree numbersGenerating the set of all three-dimensional binary arrays distinct under rotation and reflection?Distinguishing between elements of a given listFlatten sublists within a bigger listList manipulation with random elements under limiting conditionsEfficiently Evaluate a Multivariable Function on a List of TuplesTuples of elements from list excluding anything with repeated valuesDeleting duplicates only if they are a certain kind of duplicateReformatting the pattern inside a list
Drawing Quarter-Circle
How can I answer high-school writing prompts without sounding weird and fake?
Why was this sacrifice sufficient?
Looking for a simple way to manipulate one column of a matrix
Is a vertical stabiliser needed for straight line flight in a glider?
Cropping a message using array splits
What is the significance of 4200 BCE in context of farming replacing foraging in Europe?
What does it mean with the ask price is below the last price?
A musical commute to work
Two researchers want to work on the same extension to my paper. Who to help?
Adding slope values to attribute table (QGIS 3)
"Right on the tip of my tongue" meaning?
Understanding basic photoresistor circuit
How to make the table in the figure in LaTeX?
How could we transfer large amounts of energy sourced in space to Earth?
International Code of Ethics for order of co-authors in research papers
Is it a Munchausen Number?
Why do Thanos's punches not kill Captain America or at least cause some mortal injuries?
semanage not changing file context
Early arrival in Australia, early hotel check in not available
How do I compare the result of "1d20+x, with advantage" to "1d20+y, without advantage", assuming x < y?
Is it a bad idea to replace pull-up resistors with hard pull-ups?
Why in a Ethernet LAN, a packet sniffer can obtain all packets sent over the LAN?
Why does a C.D.F need to be right-continuous?
Counting elements of multidimensional list according to patterns
Specifying string patterns in DeleteCasesGenerating a list of cubefree numbersGenerating the set of all three-dimensional binary arrays distinct under rotation and reflection?Distinguishing between elements of a given listFlatten sublists within a bigger listList manipulation with random elements under limiting conditionsEfficiently Evaluate a Multivariable Function on a List of TuplesTuples of elements from list excluding anything with repeated valuesDeleting duplicates only if they are a certain kind of duplicateReformatting the pattern inside a list
$begingroup$
I have the tuples :
a = Range[0, 2];
l2 = Tuples[a, a]
which gives
0, 0, 0, 1, 0, 2, 1, 0, 1, 1, 1, 2, 2, 0, 2, 1, 2,
2
I want to find all tuples which contain number 1 exactly once.
A possible solution would be :
l21 = Cases[l2, 1, x_ /; x != 1 | x_ /; x != 1, 1]
For the three - dimensional case it would be something like this :
l3 = Tuples[a, a, a];
Cases[l3, 1, x_ /; x != 1, y_ /; y != 1 | x_ /; x != 1, 1,
y_ /; y != 1 | x_ /; x != 1, y_ /; y != 1, 1]
What would be a shorter way to use patterns in Cases for higher
dimensions, e.g.
Tuples[a,a,a,a,a]
list-manipulation
$endgroup$
add a comment |
$begingroup$
I have the tuples :
a = Range[0, 2];
l2 = Tuples[a, a]
which gives
0, 0, 0, 1, 0, 2, 1, 0, 1, 1, 1, 2, 2, 0, 2, 1, 2,
2
I want to find all tuples which contain number 1 exactly once.
A possible solution would be :
l21 = Cases[l2, 1, x_ /; x != 1 | x_ /; x != 1, 1]
For the three - dimensional case it would be something like this :
l3 = Tuples[a, a, a];
Cases[l3, 1, x_ /; x != 1, y_ /; y != 1 | x_ /; x != 1, 1,
y_ /; y != 1 | x_ /; x != 1, y_ /; y != 1, 1]
What would be a shorter way to use patterns in Cases for higher
dimensions, e.g.
Tuples[a,a,a,a,a]
list-manipulation
$endgroup$
$begingroup$
l2 = Tuples[a, 2]
andl3 = Tuples[a, 3]
are a bit simpler and more easily extended to higher dimensions.
$endgroup$
– Roman
May 7 at 11:58
add a comment |
$begingroup$
I have the tuples :
a = Range[0, 2];
l2 = Tuples[a, a]
which gives
0, 0, 0, 1, 0, 2, 1, 0, 1, 1, 1, 2, 2, 0, 2, 1, 2,
2
I want to find all tuples which contain number 1 exactly once.
A possible solution would be :
l21 = Cases[l2, 1, x_ /; x != 1 | x_ /; x != 1, 1]
For the three - dimensional case it would be something like this :
l3 = Tuples[a, a, a];
Cases[l3, 1, x_ /; x != 1, y_ /; y != 1 | x_ /; x != 1, 1,
y_ /; y != 1 | x_ /; x != 1, y_ /; y != 1, 1]
What would be a shorter way to use patterns in Cases for higher
dimensions, e.g.
Tuples[a,a,a,a,a]
list-manipulation
$endgroup$
I have the tuples :
a = Range[0, 2];
l2 = Tuples[a, a]
which gives
0, 0, 0, 1, 0, 2, 1, 0, 1, 1, 1, 2, 2, 0, 2, 1, 2,
2
I want to find all tuples which contain number 1 exactly once.
A possible solution would be :
l21 = Cases[l2, 1, x_ /; x != 1 | x_ /; x != 1, 1]
For the three - dimensional case it would be something like this :
l3 = Tuples[a, a, a];
Cases[l3, 1, x_ /; x != 1, y_ /; y != 1 | x_ /; x != 1, 1,
y_ /; y != 1 | x_ /; x != 1, y_ /; y != 1, 1]
What would be a shorter way to use patterns in Cases for higher
dimensions, e.g.
Tuples[a,a,a,a,a]
list-manipulation
list-manipulation
edited May 7 at 12:01
user64494
3,68511222
3,68511222
asked May 7 at 11:44
user57467user57467
663
663
$begingroup$
l2 = Tuples[a, 2]
andl3 = Tuples[a, 3]
are a bit simpler and more easily extended to higher dimensions.
$endgroup$
– Roman
May 7 at 11:58
add a comment |
$begingroup$
l2 = Tuples[a, 2]
andl3 = Tuples[a, 3]
are a bit simpler and more easily extended to higher dimensions.
$endgroup$
– Roman
May 7 at 11:58
$begingroup$
l2 = Tuples[a, 2]
and l3 = Tuples[a, 3]
are a bit simpler and more easily extended to higher dimensions.$endgroup$
– Roman
May 7 at 11:58
$begingroup$
l2 = Tuples[a, 2]
and l3 = Tuples[a, 3]
are a bit simpler and more easily extended to higher dimensions.$endgroup$
– Roman
May 7 at 11:58
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
Select[l2, Count[#, 1] == 1 &]
Pick[l2, Counts[#][1] & /@ l2, 1]
Pick[l2, Total@Transpose[1-Unitize[l2-1]], 1]
Cases[Except[1] ..., 1, Except[1] ...]@l2
0, 1, 1, 0, 1, 2, 2, 1
Select[l3, Count[#, 1] == 1 &]
Pick[l3, Counts[#][1] & /@ l3, 1]
Pick[l3, Total@Transpose[1-Unitize[l3-1]], 1]
Cases[Except[1] ..., 1, Except[1] ...]@l3
0, 0, 1, 0, 1, 0, 0, 1, 2, 0, 2, 1, 1, 0, 0, 1, 0,
2, 1,
2, 0, 1, 2, 2, 2, 0, 1, 2, 1, 0, 2, 1, 2, 2, 2, 1
$endgroup$
$begingroup$
Thanks! So easy!
$endgroup$
– user57467
May 7 at 11:50
$begingroup$
@user57467, you are welcome.
$endgroup$
– kglr
May 7 at 11:53
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f197852%2fcounting-elements-of-multidimensional-list-according-to-patterns%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Select[l2, Count[#, 1] == 1 &]
Pick[l2, Counts[#][1] & /@ l2, 1]
Pick[l2, Total@Transpose[1-Unitize[l2-1]], 1]
Cases[Except[1] ..., 1, Except[1] ...]@l2
0, 1, 1, 0, 1, 2, 2, 1
Select[l3, Count[#, 1] == 1 &]
Pick[l3, Counts[#][1] & /@ l3, 1]
Pick[l3, Total@Transpose[1-Unitize[l3-1]], 1]
Cases[Except[1] ..., 1, Except[1] ...]@l3
0, 0, 1, 0, 1, 0, 0, 1, 2, 0, 2, 1, 1, 0, 0, 1, 0,
2, 1,
2, 0, 1, 2, 2, 2, 0, 1, 2, 1, 0, 2, 1, 2, 2, 2, 1
$endgroup$
$begingroup$
Thanks! So easy!
$endgroup$
– user57467
May 7 at 11:50
$begingroup$
@user57467, you are welcome.
$endgroup$
– kglr
May 7 at 11:53
add a comment |
$begingroup$
Select[l2, Count[#, 1] == 1 &]
Pick[l2, Counts[#][1] & /@ l2, 1]
Pick[l2, Total@Transpose[1-Unitize[l2-1]], 1]
Cases[Except[1] ..., 1, Except[1] ...]@l2
0, 1, 1, 0, 1, 2, 2, 1
Select[l3, Count[#, 1] == 1 &]
Pick[l3, Counts[#][1] & /@ l3, 1]
Pick[l3, Total@Transpose[1-Unitize[l3-1]], 1]
Cases[Except[1] ..., 1, Except[1] ...]@l3
0, 0, 1, 0, 1, 0, 0, 1, 2, 0, 2, 1, 1, 0, 0, 1, 0,
2, 1,
2, 0, 1, 2, 2, 2, 0, 1, 2, 1, 0, 2, 1, 2, 2, 2, 1
$endgroup$
$begingroup$
Thanks! So easy!
$endgroup$
– user57467
May 7 at 11:50
$begingroup$
@user57467, you are welcome.
$endgroup$
– kglr
May 7 at 11:53
add a comment |
$begingroup$
Select[l2, Count[#, 1] == 1 &]
Pick[l2, Counts[#][1] & /@ l2, 1]
Pick[l2, Total@Transpose[1-Unitize[l2-1]], 1]
Cases[Except[1] ..., 1, Except[1] ...]@l2
0, 1, 1, 0, 1, 2, 2, 1
Select[l3, Count[#, 1] == 1 &]
Pick[l3, Counts[#][1] & /@ l3, 1]
Pick[l3, Total@Transpose[1-Unitize[l3-1]], 1]
Cases[Except[1] ..., 1, Except[1] ...]@l3
0, 0, 1, 0, 1, 0, 0, 1, 2, 0, 2, 1, 1, 0, 0, 1, 0,
2, 1,
2, 0, 1, 2, 2, 2, 0, 1, 2, 1, 0, 2, 1, 2, 2, 2, 1
$endgroup$
Select[l2, Count[#, 1] == 1 &]
Pick[l2, Counts[#][1] & /@ l2, 1]
Pick[l2, Total@Transpose[1-Unitize[l2-1]], 1]
Cases[Except[1] ..., 1, Except[1] ...]@l2
0, 1, 1, 0, 1, 2, 2, 1
Select[l3, Count[#, 1] == 1 &]
Pick[l3, Counts[#][1] & /@ l3, 1]
Pick[l3, Total@Transpose[1-Unitize[l3-1]], 1]
Cases[Except[1] ..., 1, Except[1] ...]@l3
0, 0, 1, 0, 1, 0, 0, 1, 2, 0, 2, 1, 1, 0, 0, 1, 0,
2, 1,
2, 0, 1, 2, 2, 2, 0, 1, 2, 1, 0, 2, 1, 2, 2, 2, 1
edited May 7 at 12:04
answered May 7 at 11:49
kglrkglr
192k10213432
192k10213432
$begingroup$
Thanks! So easy!
$endgroup$
– user57467
May 7 at 11:50
$begingroup$
@user57467, you are welcome.
$endgroup$
– kglr
May 7 at 11:53
add a comment |
$begingroup$
Thanks! So easy!
$endgroup$
– user57467
May 7 at 11:50
$begingroup$
@user57467, you are welcome.
$endgroup$
– kglr
May 7 at 11:53
$begingroup$
Thanks! So easy!
$endgroup$
– user57467
May 7 at 11:50
$begingroup$
Thanks! So easy!
$endgroup$
– user57467
May 7 at 11:50
$begingroup$
@user57467, you are welcome.
$endgroup$
– kglr
May 7 at 11:53
$begingroup$
@user57467, you are welcome.
$endgroup$
– kglr
May 7 at 11:53
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f197852%2fcounting-elements-of-multidimensional-list-according-to-patterns%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
l2 = Tuples[a, 2]
andl3 = Tuples[a, 3]
are a bit simpler and more easily extended to higher dimensions.$endgroup$
– Roman
May 7 at 11:58