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













2












$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]









share|improve this question











$endgroup$











  • $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
















2












$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]









share|improve this question











$endgroup$











  • $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














2












2








2





$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]









share|improve this question











$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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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] 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
















$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











1 Answer
1






active

oldest

votes


















4












$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







share|improve this answer











$endgroup$












  • $begingroup$
    Thanks! So easy!
    $endgroup$
    – user57467
    May 7 at 11:50










  • $begingroup$
    @user57467, you are welcome.
    $endgroup$
    – kglr
    May 7 at 11:53











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
);



);













draft saved

draft discarded


















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









4












$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







share|improve this answer











$endgroup$












  • $begingroup$
    Thanks! So easy!
    $endgroup$
    – user57467
    May 7 at 11:50










  • $begingroup$
    @user57467, you are welcome.
    $endgroup$
    – kglr
    May 7 at 11:53















4












$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







share|improve this answer











$endgroup$












  • $begingroup$
    Thanks! So easy!
    $endgroup$
    – user57467
    May 7 at 11:50










  • $begingroup$
    @user57467, you are welcome.
    $endgroup$
    – kglr
    May 7 at 11:53













4












4








4





$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







share|improve this answer











$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








share|improve this answer














share|improve this answer



share|improve this answer








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
















  • $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

















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form