Skip to main content
40 votes
Accepted

Remove noise from data

You could try BilateralFilter: ...
Niki Estner's user avatar
  • 36.1k
29 votes
Accepted

Performance of Select

res1 = Select[coordinates, #[[1]] > 6 && #[[1]] < 7 &]; // AbsoluteTiming // First 6.997629 ...
kglr's user avatar
  • 396k
23 votes
Accepted

Deleting duplicates after n-occurrences

I think you'll find this faster: dd[list_, n_] := Module[{pi = Flatten[Values[PositionIndex[list][[All, ;; UpTo@n]]]]}, list[[Sort@pi]]]; Using ...
ciao's user avatar
  • 25.8k
22 votes

Deleting sublists from lists

ReplaceRepeated is fine for short lists but it will get very slow if the list is long, because it starts over from the beginning of the list after each replacement. ...
Mr.Wizard's user avatar
  • 272k
22 votes

Performance of Select

Slightly faster than @kglr's solution is to use Clip: ...
Carl Woll's user avatar
  • 131k
22 votes
Accepted

How to construct a list of lengths efficiently

You can use the usual UnitStep + Total tricks: ...
Carl Woll's user avatar
  • 131k
21 votes
Accepted

Finding outliers in 2D and 3D numerical data

The question title poses a good question, although the question formulation is somewhat specialized and misplaced (as mentioned in a comment). This answer provides data and a method description ...
Anton Antonov's user avatar
21 votes

Find duplicates in list of InfiniteLine

DeleteDuplicates[lines, RegionWithin] {InfiniteLine[{{0, 0}, {1, 0}}], InfiniteLine[{{0, 1}, {1, 0}}]} Also ...
kglr's user avatar
  • 396k
21 votes
Accepted

Deleting sublists from lists

Try testList //. {a___, aa_Symbol, _Integer, bb_Symbol, b___} :> {a, aa, bb, b} {a, b, c, 4, 5, d, e, f, g, 4} ...
jjc385's user avatar
  • 3,473
21 votes
Accepted

Removing outliers from data

You could take a look at the built-in functions FindAnomalies and DeleteAnomalies. We can use ...
Carl Lange's user avatar
  • 13.1k
20 votes

Remove noise from data

I would suggest using a median filter with small radius to eliminate the large spikes, then a mean filter to smooth the remaining signal. @Xavier essentially combines these two filters by using ...
KennyColnago's user avatar
  • 15.3k
20 votes

Deleting sublists from lists

Mr.Wizard inspired me to improve. While his recursive approach is elegant, the problem clearly can be done linearly. Indeed: ...
jjc385's user avatar
  • 3,473
17 votes
Accepted

How to get cell boundaries in the image?

...
corey979's user avatar
  • 24k
17 votes
Accepted

Delete redundant {x,y} pairs

...
kglr's user avatar
  • 396k
17 votes

How can I code a "smart" version of Chop?

We can turn to unsupervised machine learning in the form of clustering algorithms to try to automate this intuition. Here are a few different results using ...
C. E.'s user avatar
  • 70.7k
16 votes

Finding the two pairs in a list of pairs that minimize and maximize a given function

list = {{1, 2}, {5, 3}, {9, 2}} func = 2*#[[1]] + #[[2]] &; Through[{MinimalBy[func], MaximalBy[func]}[list]] ...
Karsten7's user avatar
  • 27.5k
16 votes

Deleting sublists from lists

The slowest part of @MrWizard's solution is the conversion to 1s and 0s. Here is a faster way to do this conversion: ...
Carl Woll's user avatar
  • 131k
16 votes
Accepted

Ordered RandomSample

Avoiding Sort makes it a bit faster ...
Coolwater's user avatar
  • 20.3k
16 votes
Accepted

Most efficient numerical selectBetween

Varying samples (Updated to include internal function) For varying samples, I think the best non-compiled method is to use Pick as you did. You can speed up the ...
Carl Woll's user avatar
  • 131k
16 votes
Accepted

Given a list of integers, find the largest sum of a contiguous subsequence

f[l_] := Module[{sl = Flatten@MaximalBy[Subsequences[l], Total]}, {Total[sl], sl}] f[{1, 2, 3, 4, 5, -1, 7, -4, -2}] (* {21, {1, 2, 3, 4, 5, -1, 7}} *)
bbgodfrey's user avatar
  • 61.6k
16 votes
Accepted

List letters at even- or odd-numbered positions in Alphabet

Much simpler solution: Alphabet[][[1 ;; All ;; 2]] Alphabet[][[2 ;; All ;; 2]]
Sjoerd Smit's user avatar
  • 23.6k
15 votes
Accepted

Writing Faster Mathematica Code - Sow and Reap?

Here's a million points processed in half a second: ...
Michael E2's user avatar
  • 237k
15 votes

Solving chess bishop problem

Mathematica's FindIndependentVertexSet can find maximal independent set (size 14 =2n-2) by default. The following finds "12". I have not explored symmetries as I am ...
ubpdqn's user avatar
  • 61.6k
15 votes

Deleting sublists from lists

f0 = Flatten @ DeleteCases[{_Integer}] @ SplitBy[#, IntegerQ] &; f0 @ testList {a, b, c, 4, 5, d, e, f, g} Timings between those of Mr.Wizard's ...
kglr's user avatar
  • 396k
15 votes

How to construct a list of lengths efficiently

BinCounts and Accumulate combination is faster than all the methods posted so far: ...
kglr's user avatar
  • 396k
15 votes
Accepted

Using Select on Dataset with missing keys

You can use the Slot function rather than #slot. This is nearly as fast as the #slot implementation, but doesn't cause this issue. ...
Carl Lange's user avatar
  • 13.1k
15 votes

DeleteCases for once only

You can Fold the four-argument form of DeleteCases: ...
kglr's user avatar
  • 396k
15 votes
Accepted

How can I speed up processing with DeleteCases?

As kglr says, you should use RegionMember. However, instead of mapping RegionMember (which is basically what his ...
Carl Woll's user avatar
  • 131k
15 votes
Accepted

Association vs Pair - Creation performance, Selection performance

Simply use keys = Range[1000000]; vals = Range[1000000]^2; result = Pick[vals, PrimeQ[keys]]; to get the best of both worlds (zero construction cost and even ...
Henrik Schumacher's user avatar
15 votes
Accepted

Check if a string is a date

The pattern "DatePattern[{"Year", "Month", "Day"}]" will match a date. You may use it e.g. inside "Select" like: ...
Daniel Huber's user avatar
  • 52.7k

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