14 votes

Determine repeating number of a given number and corresponding position

If you have Mma version >= 10.1 , this does the job : ...
andre314's user avatar
  • 18.2k
14 votes

How to total the amount of zeros in a binary matrix

ClearAll[countZ] countZ = 1 ## & @@ Dimensions @ # - Total[#, 2] &; countZ@binarym 17 Timings: ...
kglr's user avatar
  • 392k
12 votes
Accepted

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

n = 10000; list = RandomReal[{0, 1}, n]; a = 0.3; b = 0.6; UnitStep[list - a].UnitStep[b - list]
Henrik Schumacher's user avatar
12 votes

Accumulated instance count of each list element

accumulateCounts := Module[{c$}, c$[_] = 0; Map[PreIncrement@*c$]] accumulateCounts @ {m, i, s, s, i, s, s, i, p, p, i} ...
kglr's user avatar
  • 392k
11 votes
Accepted

Determine repeating number of a given number and corresponding position

I think this question may still be considered a duplicate of Finding negative sequences in a large list: optimization but it seems to permit a somewhat simpler solution which I would like to post. ...
Mr.Wizard's user avatar
  • 271k
11 votes
Accepted

`Count` for `SparseArray`

I can't speak to why exactly it doesn't work, but as for a workaround... If you want to simply count how many values are unspecified, you can take the product of the dimensions (to get the ...
thorimur's user avatar
  • 9,010
10 votes
Accepted

Count Column Elements in a Matrix

I think the simplest version is: Total @ Unitize @ mat {2, 2, 2}
Carl Woll's user avatar
  • 130k
10 votes
Accepted

How to count the number of eggshells in the image

Here's one way: {r, g, b} = ColorSeparate[Import["https://i.imgur.com/PZNt7JQ.jpg"]]; bw = MorphologicalBinarize[b, 0.5] ...
bill s's user avatar
  • 68.8k
10 votes
Accepted

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

...
Kuba's user avatar
  • 137k
10 votes
Accepted

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

titanic[KeyValueMap[Append[#, "counts" -> #2] &]@*Counts, {"class", "sex"}]
kglr's user avatar
  • 392k
9 votes
Accepted

How to make my fuction return a step count

In 2D: ...
Dr. belisarius's user avatar
9 votes

Determine repeating number of a given number and corresponding position

...
march's user avatar
  • 23.2k
9 votes
Accepted

Count number of occurences of particular numbers in list

BinCounts[napajecky, {0,85,5}] (* {5, 7, 8, 12, 3, 6, 7, 2, 1, 0, 1, 0, 0, 0, 0, 0, 0} *) Notice that the range goes to 85 so that the last bin is $[80,85)$ ...
Roman's user avatar
  • 46.9k
8 votes

Determine repeating number of a given number and corresponding position

This one's just for fun, kind of a reverse-codegolf ...
Jason B.'s user avatar
  • 67.9k
8 votes
Accepted

Count does not tally with total

It's because each time you Count (that is, for each element of Range[6]) you're creating a new array of ...
aardvark2012's user avatar
  • 5,424
8 votes

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

I can propose two things that speed up the letter counting tremendously: 1.) Use ToCharacterCode to convert your strings to packed arrays of integers. 2.) Use a ...
Henrik Schumacher's user avatar
8 votes
Accepted

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

You can try Tally lst = {"aa bb", "cc dd", "aa bb", "aa bb", "cc dd", "ww ss", "ss ss", "kk mm"}; Tally[lst] Edit by ...
Nasser's user avatar
  • 142k
8 votes

Program that can count deficient numbers

Count[ILD`DeficientNumberQ /@ Range[100], True] 76 Alternatively, you can use DivisorSigma[1, n] or ...
kglr's user avatar
  • 392k
8 votes

Values of counting functions

You can use SparseArray and Accumulate to assemble a vector cvec so that ...
Henrik Schumacher's user avatar
8 votes
Accepted

Accumulated instance count of each list element

...
Syed's user avatar
  • 49k
7 votes
Accepted

Repeated consecutive values above a threshold

Fundamental operation: ...
Kuba's user avatar
  • 137k
7 votes

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

You can use LetterCounts as follows: ...
kglr's user avatar
  • 392k
7 votes

Count number of occurences of particular numbers in list

res = Lookup[Counts[napajecky], Range[5, 80, 5], 0] {7, 8, 12, 3, 6, 7, 2, 1, 0, 1, 0, 0, 0, 0, 0, 0}
Coolwater's user avatar
  • 20.2k
7 votes

Program that can count deficient numbers

From Wikipedia In number theory, a deficient number or defective number is a number n for which the sum of divisors σ(n)<2n Therefore ...
Nasser's user avatar
  • 142k
7 votes

`Count` for `SparseArray`

saCount[s_SparseArray, a_] := Block[{v = s["NonzeroValues"] }, Count[v, a] + If[a == s["Background"], Times @@ Dimensions[s] - Length@v, 0]] saCount[a, 0] <...
kglr's user avatar
  • 392k
7 votes

How do I count zeros in sublists?

Try this example matrix=RandomInteger[1,{5,5}] returns this {{0,1,0,1,1},{0,1,0,0,1},{1,0,1,0,1},{1,1,1,0,0},{0,0,0,1,0}} ...
Bill's user avatar
  • 11.9k
6 votes

Determine repeating number of a given number and corresponding position

You could use Position[] and Split[_, #2 - #1 == 1 &] ...
xyz's user avatar
  • 605
6 votes

Determine repeating number of a given number and corresponding position

It seems that I'm late to the party, yet another one-liner: Thread[{Most@Prepend[Accumulate@# + 1, 1], #}][[3/2-data[[1]]/2;; ;; 2]] &[Length /@ Split@data]
Wjx's user avatar
  • 9,558
6 votes

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

...
george2079's user avatar
  • 38.9k
6 votes

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

This isn't as fast as the UnitStep method given by Henrik, but for many applications having the most efficient method isn't necessary. ...
Jason B.'s user avatar
  • 67.9k

Only top scored, non community-wiki answers of a minimum length are eligible