Skip to main content

Questions tagged [counting]

Questions on counting subparts of expressions, based on certain criteria. This is to be used with primary tags such as list-manipulation or string-manipulation, with the primary tag indicating the specific use case.

Filter by
Sorted by
Tagged with
2 votes
1 answer
109 views

Efficiently Finding Weighted Integer Partitions

Suppose we have some list of natural numbers $\{ 1, 2, \dots, N \}$ and each natural number $i$ has a 'weight' $w_i$. I would like to generate the all the integer partitions which satisfy the ...
MathPhysPlague's user avatar
1 vote
1 answer
43 views

Method of assigning a number to the number of attempts that have appeared from it, with the first attempt appearing as number 1

I want to assign the first trial that appears as number 1 and the number of trials that appear from there as elements of the list, plus a number. At first, The following listA consisting of {a, b}. In ...
hare's user avatar
  • 436
7 votes
8 answers
472 views

Accumulated instance count of each list element

Given a list with repeated elements, for example: list = {m, i, s, s, i, s, s, i, p, p, i} I'd like to determine, for each position in the list, how many times the ...
thecommexokid's user avatar
3 votes
4 answers
144 views

Is there a better way to calculate the number of codewords of weight $i$ in a list of codewords?

Background Info I am interested in a better way of doing the following: I want to find the weights of the following codewords (the weight of a codeword here can be defined as the number of nonzero ...
am567's user avatar
  • 501
6 votes
6 answers
429 views

Count all co-occurances of a pair of strings in a list of lists

I am trying to obtain a co-occurance matrix for pairs of names in a collection of groups of names. So, I have a collection of letters in small groups, such as ...
apg's user avatar
  • 2,155
0 votes
0 answers
58 views

Using Count[] on a numerical list with approximate numbers

I have a matrix, SpinOp, for which I obtain the Eigensystem using {evalSpinOp,evecSpinOp} = Eigensystem[SpinOp]. I need to ...
Nitin's user avatar
  • 431
8 votes
5 answers
288 views

Values of counting functions

I have a table of integers, say A, and consider the counting function C, which, for a given x, gives the number of elements in A which are less or equal to x. Next, I want to plot C(x) in some range, ...
Maciej Ulas's user avatar
4 votes
1 answer
244 views

Count occurences of number in list of lists

I have a nested list of numbers, something like satisfied = {{1, 5, 6, 2, 1, 2}, {1, 5,,8, 6}, ..., {5, 6, 1}} and I want to count the number of occurences of 1 in each list. I know there is 1000 of ...
Ka Pe's user avatar
  • 43
2 votes
4 answers
226 views

Counting number of points in fluctuating lines that fall within a circle

I have a list of points pts that fluctuate around some mean line. pts is pre-sorted by the projection of the points onto this ...
az123p's user avatar
  • 239
4 votes
4 answers
214 views

Counting number of real and complex entries in a list

Say I have a list like this ...
user824530's user avatar
0 votes
1 answer
31 views

Confusing abnormalities observed when counting a specific operator in an expression [duplicate]

Recently I have met with some confusing abnormalities when trying to determine if there is a specific operator (usually Plus[] ) in an expression by programming. ...
AlbertLew's user avatar
  • 483
5 votes
3 answers
164 views

Listing all Index Possibilities Given a Vector and Indexed Set

Let's say I am given a vector $v=(5,2,-2,-4,3)^T$ and $\alpha \in \{-1,1\} $. I want to find all indices $(\alpha,i)$ such that $\alpha v_i >0$, where $v_i$ is the $i$th entry of the vector $v$ ...
Vegeta the Prince of Saiyans's user avatar
8 votes
6 answers
326 views

How to sort and extract a list containing products

I've some difficulties with lists containing products as elements, e.g. list = {A B A, A K B, A K R}, where A and B are from the same 'family', let's call it sector ...
Nathanael Noir's user avatar
1 vote
1 answer
80 views

Compute the length of each string in a set [closed]

Say I have done some computation, and it gives me the following set of string: ...
JacobsonRadical's user avatar
2 votes
1 answer
64 views

Counting the number of elements

I have the following output: {{{0, 1}}, {{1, 1}, {1, 2}}, {{2, 1}, {2, 3}}, {{3, 1}, {3, 2}, {3, 3}, {3, 4}}} Using Length[] on ...
Jan Eerland's user avatar
  • 2,001
1 vote
0 answers
122 views

How to count the amount of times an element appears seperately within a nested list [closed]

Beginner at using Mathematica, and having trouble with nested lists. For example, the following output for 15 coinflips every day for a year: ...
SgtPorkchops's user avatar
2 votes
1 answer
43 views

ResetDirectory causes a fail on stored file names

Consider some directory dir with sub dirs and files. Our aim is to count the no of files in dir (not in sub-dirs, just the dir.) ...
lineage's user avatar
  • 1,154
1 vote
1 answer
69 views

Counting the number of occurrences of all groupings (consecutive occurrences of the same number) in a list

If the variable "digits" contains a sequence of numbers how to count how many times each grouping of a number occurs? For instance, for number $1$ how many times it occurs once consequitivly ...
thinkingdude's user avatar
2 votes
2 answers
252 views

Counting the number of occurrences of specific values in a list in specific intervals

If the variable "digits" contains 10,000 digits from 0 to 9. How can the number of occurrences of 1s and 2s be counted in every 1000 digit intervals, that is to say the number of 1s and 2s ...
thinkingdude's user avatar
0 votes
1 answer
75 views

Count heads: e.g. neglect all terms $\sin(x) \sin (y) \sin (z) \sin (w)$ for all values of the argument

I have a polynomial (functional) expression $E[F]$ in terms of a function $F$. I want to take an $F$-cube truncation in the sense that I want to and make terms of the form $F[w]F[x]F[y]F[z]$ vanish ...
João 's user avatar
  • 155
4 votes
2 answers
411 views

How do I count zeros in sublists?

I have an array RandomInteger[1,{100,100}]. How do I count zeros in each sublist so that I have a list which gives the number of zeros of each sublist in the array?
Garfield's user avatar
7 votes
1 answer
295 views

In Wolfram Mathematica, who do I query the result of a Counts operation efficiently and conveniently?

Setup Say, I'm given a dataset, like the one below: titanic = ExampleData[{"Dataset", "Titanic"}]; titanic Answering with: And I want to count the occurrences ...
nanitous's user avatar
  • 285
10 votes
2 answers
306 views

`Count` for `SparseArray`

Why does Count not work with SparseArrays, and is there any function I can use to replace it? What would be an efficient ...
Daniel's user avatar
  • 509
1 vote
2 answers
82 views

Counting the number of rows that contains specific numbers in specific cells

I'm trying to find a way to count the number of rows in a matrix that contains specific elements in specific cells. For example, suppose I have the following matrix ...
Andeanlll's user avatar
  • 423
-1 votes
1 answer
39 views

Adding up a list of rules

Here's the problem: I take a count of a count, so that I end up with a list in this format: Table[Counts@Counts@Join[dKm[[i]], Pick[data1, ccKMedoid, i]], {i, 5}] ...
Illari's user avatar
  • 409
1 vote
1 answer
46 views

Putting a Count function for a matrix, in a loop

previously i had a doubt on how to assign different rows with certain values using a special function, which i later figured out by using the far more superior "DO" Loop. At present i have two ...
NoNombre's user avatar
5 votes
3 answers
258 views

Program that can count deficient numbers

Using Mathematica, I want to make program which can solve the following question. What is the number of deficient numbers less than 100? Please help me.
김태진's user avatar
3 votes
3 answers
459 views

count conditional items in list

I have a list of the form: {1,1, (1 if x>y, -1 if y>=x), -1} I want to count the number of 1's in the list. The output I'm looking for is something of the ...
naomig's user avatar
  • 343
2 votes
0 answers
107 views

Finding percentage of points within tilted ellipse?

I am trying to find the number of data points that I have that are within a tilted ellipse that I have generated to represent the 68% confidence region. I generated some data using: ...
Illari's user avatar
  • 409
1 vote
2 answers
92 views

Using Count and Rotate left

Q. Use RotateLeft and Count to find the number of planets detected by each method, presenting the result in a list of the form {{D, n1}, {R, n2}, {T, n3}}. ...
12345's user avatar
  • 199
2 votes
2 answers
285 views

Count number of individual operations

Im interested in counting the number of operations required to evaluate a given formula. Let me give you an example. Lets say I have entered the expression $\dfrac{\operatorname{Sqrt}[\operatorname{...
Arji's user avatar
  • 1,134
9 votes
6 answers
3k views

How do I count the number of elements in a list which are between two determined values?

I have a long list (apprx. 10000 elements) of numbers. I want to count the number of elements between two determined vallues a and ...
mattiav27's user avatar
  • 6,747
0 votes
1 answer
276 views

Fast way to count distinct pairs of integers

I have a association list, S, whose size is about 5*10^4. I also have a function F which takes in ordered pairs of elements from S, and spits out ordered pairs of integers. There is some amount of ...
Pace Nielsen's user avatar
4 votes
1 answer
110 views

Counting the number of strings starting with "t" and containing 2 vowels and 2 consonants

I generated a list of strings that match the criteria in the title as follows: ...
user170231's user avatar
  • 1,611
8 votes
3 answers
855 views

Count number of occurences of particular numbers in list

I have a list of numbers which I have rounded and now all numbers are divisible by 5. ...
Vocis's user avatar
  • 195
4 votes
2 answers
65 views

Making polynomials representing frequency of a character in a list

Suppose I have the following list: l={{"a"}, {"a", "h"}, {"a", "d", "k", "r", "v"}, {"a", "b", "c", "k"}, {"a", "b", "c", "s", "u"}} this list made of the ...
Wiliam's user avatar
  • 3,016
2 votes
1 answer
447 views

How can I get the count of how many times a string appears in my list? [closed]

I have a list of strings, like so: {"aa bb", "cc dd", "aa bb", "aa bb", "cc dd", "ww ss", "ss ss", "kk mm"} I know WordCounts ...
zongxian's user avatar
  • 901
3 votes
3 answers
153 views

How to creates a Counts[] function that includes zero?

In the following example, I'm trying to how many times each integer 1-n appears in list 'a'. But if an element did not appear in a list, Counts[] creates an association that returns the element ...
Jerry Guern's user avatar
  • 4,612
0 votes
1 answer
121 views

Count sublists containing certain strings

I have a nested list which looks like: and I would like to count the following: all sublists containing {n_,n_} && {n_,n_,n_} all sublists containing {l_,l_} && {l_,l_,l_} all ...
Besi's user avatar
  • 119
2 votes
2 answers
85 views

Counting the number of Configurations in an Array with Constraints

Consider an array $$\{a_i\}, i=1, ..., N$$ with periodic boundary condition, i.e. $i\equiv i+N$. $a_i\in \{0, 1\}$. I would like to count the number of configurations of the array $\{a_i\}$ satisfying ...
user34104's user avatar
  • 251
12 votes
3 answers
1k views

Loop over a list of strings and increment letter count in a corresponding sublist

I have a 2D list as follows: ...
brienna's user avatar
  • 1,071
3 votes
2 answers
66 views

Bin arbitrary data using canonical ordering

I have two lists of words, nouns and verbs: ...
Stephen Powell's user avatar
6 votes
2 answers
653 views

Bigrams and TF-IDF calculation

I want to create a bag of bigrams in a set of documents and calculate the TF-IDF vector of each document. To calculate the bigram of the text I used the following code: The small example of the data (...
Kiril Danilchenko's user avatar
2 votes
1 answer
243 views

How to count the number of eggshells in the image

My goal for this is to simply count the number of eggshells in the image. Using color negate only leads to this ...
visatete's user avatar
4 votes
4 answers
199 views

How can one efficiently find the (x,y) values of the rectangles that enclose a chosen % of nonrandom data points in mathematica?

A half hour of searching for answers did not give useful results. This is typical data: I need to find the (x,y) values of at least 6 rectangles with one corner at (0,0) and the opposite corner at (...
Michael B. Heaney's user avatar
3 votes
1 answer
334 views

How many records? In a file (streaming)

I want to know how many records a file (large data) contains... with streaming...like this: ...
Cécile Meier's user avatar
2 votes
2 answers
65 views

Counting all matrices in a family obeying a certain rule

I would like to use the Count[list, pattern] method to count all 4x4 matrices with entries in $\lbrace 0 ,1 \rbrace$ that have a certain Jordan canonical form. The ...
Dan's user avatar
  • 145
0 votes
1 answer
134 views

Probability of empty urns for undistinguishable balls in distinguishable urns

Distinguishable balls in distinguishable urns is a well known problem in probability theory and can be easily simulated through Montecarlo simulations. Here we provide our code for n balls and m urns: ...
sam84's user avatar
  • 497
4 votes
4 answers
912 views

How to total the amount of zeros in a binary matrix

I have a 150 by 300 binary matrix. I would like to find the total amount of zeros in the matrix. I've been consulting online documentation for support, but am unable to use the "count" function ...
Astroturf's user avatar
  • 281
4 votes
1 answer
252 views

Count does not tally with total

I code the following to count events. Count[Table[RandomInteger[{1, 6}], {i, 10}], #] & /@ Range[6]//Total By right, if I total, I expect 10. Sometimes it ...
yaykhel's user avatar
  • 171