Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

2
votes
1answer
297 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 ...
3
votes
3answers
81 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 ...
0
votes
1answer
43 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 ...
2
votes
2answers
50 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 ...
11
votes
3answers
434 views
3
votes
2answers
43 views

Bin arbitrary data using canonical ordering

I have two lists of words, nouns and verbs: ...
6
votes
2answers
215 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 (...
2
votes
1answer
210 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 ...
4
votes
4answers
168 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 (...
3
votes
1answer
171 views

How many records? In a file (streaming)

I want to know how many records a file (large data) contains... with streaming...like this: ...
2
votes
2answers
58 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 ...
0
votes
1answer
89 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: ...
4
votes
4answers
697 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 ...
4
votes
1answer
196 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 ...
3
votes
2answers
148 views

Most common prefixes in an English corpus (Hamlet)

There are many resources online showing how to get the most frequent letters in the english language. What I'm trying to do is get the most common word prefixes in the english language - i.e, take a ...
3
votes
3answers
202 views

Count Column Elements in a Matrix [duplicate]

Let a square matrix be: mat={{1,2,3},{4,5,6},{0,0,0}}; Get a total for each column: In: Total[mat] ...
2
votes
2answers
100 views

Counting number of spheres that contain a point

I have created this set of spheres in Mathematica. The code I used to produced this is as follows: ...
1
vote
1answer
121 views

Weibull Count Process, how to build in Mathematica

I am trying to solve the following problem in MATHEMATICA: (PROBLEM SOLVED, LOOK THE FOLLOWING ANSWER) I was reading this paper: McShane et al. "Count Models Based on Weibull Interarrival Times" (...
3
votes
6answers
130 views

Finding the number of $4$-tuples of consisting of digits $1$-$6$ satisfying a certain condition

I'm trying to enumerate a sample space for an experiment in which $4$ fair $6$-sided dice are rolled such that exactly $3$ of them are $5$s or $6$s. The way I understand it, the last die must be any ...
4
votes
3answers
129 views

Opposite of Counts

I would like to reverse the effect of Counts, i.e., starting with x = <|a -> 4, b -> 2, c -> 1|> I would like ...
1
vote
1answer
51 views

Number of different terms inside mathematical expression

I have expressions of the form $OpA[x\_,y\_]$ and $OpB[x\_,y\_]$ ocurring inside mathematical expressions. I want to create a function which does the following: ...
0
votes
0answers
18 views

Count cases of number [duplicate]

h = {140, 140, 175, 160, 175, 125, 120, 105, 15, 90, 150, 175, 85, 110, 30, 60, 175, 50, 130, 70, 60, 40, 130, 135, 120, 110, 150, 110, 175, 70} I have a list of ...
0
votes
1answer
71 views

Mathematica functions for dealing with sets of integers [closed]

What are the convenient Mathematica functions, say $Func1$ and $Func2$, that if one inputs a collection of sets of numbers: $$\text{{{1,2},{3,2},{4,1},{1,2},{1,2},{4,1}}}$$ (1) $$\text{$Func1$[{{1,...
4
votes
3answers
163 views

find and count the number of solutions without multiplicity in Solve?

I would like to solve a Diophantine equation and find its solution, but I need only count one time for each $a$, i.e., when for some $a$ it found some $x,y,z$, then go to the next $a$. more precisely ...
3
votes
1answer
81 views

Repeated consecutive values above a threshold

I would like to know if a list has repeated consecutive values above a threshold. Lets say for this example the threshold is 5. ...
0
votes
1answer
96 views

Counts[list] giving unexpected result [closed]

I import some data from an .xls-file and process it by subtracting pairs of data. What I need to do is counting the total number of each difference appearing in my result list, e.g. if the result list ...
0
votes
1answer
148 views

Count gives different results depending on specification

I have a tremendous list of coordinates in which i wish to count how many times a certain X appears. I use count and found accidentally, that in a loop script and individually, it gives wrong results ...
1
vote
2answers
248 views

Determine the number of times a function will be called

I have a function func[x], which is rather slow to evaluate. It gets called (multiple times) inside other expressions; I'd like to know how many times it gets called (without actually evaluating the ...
4
votes
2answers
99 views

How do I count the TOTAL number of “Subsection” cells in a notebook externally?

I can count the number of "Subsection" cells in a notebook by evaluating the following code at the BOTTOM of the notebook. ...
10
votes
9answers
980 views

Determine repeating number of a given number and corresponding position

For instance, the data is as follows: data = {1, 1, 1, -1, -1, 1, 1, -1} The target output when determining how many times "1"...
1
vote
1answer
124 views

Counting the rows of a list where the order of numbers in the row doesn't matter

I am trying to make a computation with a large set of rows. As a sample, suppose I have a list of numbers with rows and columns like such: ...
-2
votes
1answer
37 views

How to renew a value when a value is larger than it, counting the time of the record being broken at the same time [duplicate]

I have a given value and is it possible that after some calculation, when the calculated result is larger than the given value, the given value can be set as the value that is larger than it? Other ...
5
votes
1answer
143 views

How to make my fuction return a step count

I am new to mathematica, and I have this 3d random walker program which runs with a fixed (given) amount of steps. What I want it to do is to run forever but stop when two walkers collide (aka have ...
9
votes
2answers
203 views

How to make CounterIncrement step in increments of 2

Is it possible to make counters that step in increments other than 1? The default for CounterIncrements seems to be 1 and there's no other documentation on what ...
1
vote
1answer
70 views

Using a prompt to set options

I am creating a toolbar. One of the buttons on my toolbar is this setcounter button below. ...
18
votes
4answers
3k views

How to count number of small dots in a picture

I have this picture of small particles in a polymer film. I want to count how many particles in the figure, so that I can have a rough estimation of the particle density. But the image quality is poor,...
4
votes
4answers
264 views

Best way to count this?

I'm trying to use the Count function for this purpose, but it's not working how I'd like it to. Does anybody know a simple way to do this counting? I would like to be counting the number of "p"s in ...
2
votes
2answers
100 views

Length of a disjunction

Simple question: I'm trying to count the number of Roots to an equation. But both Length[x==1] and ...
7
votes
1answer
290 views

Optimal Binarize value for counting experiment

I am currently working on a physics experiment where I count particles. I have looked at and used a bit of code from the following sources: Cell counting from an image file and Count Elements in Image ...
3
votes
1answer
388 views

Count two or more equal consecutive elements in a list and create histogram

I have a list generated by: list = RandomInteger[{1}, 100] it contains only 0's and 1's ...
6
votes
2answers
471 views

Count the number of regions made by Lissajous curve

How many disconnected regions does Lissajous curve divide the plane into? For example: Let g = ParametricPlot[{Sin[2 t], Sin[t]}, {t, 0, 2 π}] The number of ...
8
votes
4answers
2k views

Count elements of a list

Let's create a random list n = 100; data = Table[{RandomReal[{0, 2}], RandomReal[{-1, 1}]}, {i, 0, n}] Now we divide the $(x,y)$ plane into four sectors with the ...
1
vote
1answer
91 views

Transform List from {a,a,b,b,b,c} to {{a,2},{b,3},{c,1}} [closed]

The title pretty much says it. I want to map over the solutions returned by Solve but want to avoid calculating the same thing over and over again. e.g. ...
10
votes
7answers
645 views

Counting subsequences (i.e., patterns) within a list?

I would like to count the number of subsequences in list. Say I have data given by: data = {1, 1, 1, 2, 1, 2, 2, 2, 1, 2, 1}; I would like to count the number ...
9
votes
3answers
524 views

Generalization to AllTrue, AnyTrue and NoneTrue

I am wondering if there is a natural Mathematica way to generalize those functions. To be specific, All three functions AllTrue, ...
4
votes
2answers
632 views

Counting the total number of instances of some collection of objects in a list

I have a list of some sort list = {"l1","l2","l3","l4"} and I'd like to count the sum total number of occurrences of n of the ...
3
votes
1answer
211 views

Interpreting a formula from Graph Theory - where do x and y come from?

I'm trying to understand the generating function for OEIS A062734, which is in Mathematica. Essentially, despite knowing no Mathematica at all, I think I can parse most of it, but where do $x$ and $y$ ...
4
votes
2answers
107 views

Count the number of element repeats at various distances

I have a function of x: f[x_] := Abs[Extract[list, x + n] - Extract[list, x]] I then apply this: ...
15
votes
6answers
2k views

Quickly test if all element in list is the same

I'm running a Monte Carlo simulation. At the end, I want to count how many simulations return a list of same element. My problem: ...
7
votes
2answers
318 views

Why doesn't this pattern work?

I want the in-built function Count to count the elements in a list which are greater than a value. Example: ...