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 ...
user avatar
11 votes
Accepted

How can I use variables instead of slots in DeleteCases?

...
user avatar
  • 51.5k
11 votes

How can I use variables instead of slots in DeleteCases?

Pick could also be useful: Pick[tuples, Function[{a, b, c}, a + 2 b + c == 0] @@@ tuples, False]
user avatar
  • 5,089
11 votes

How can I apply a function only to even-index elements of a list?

I changed D to Dd: MapAt[Dd, A, 2 ;; ;; 2]
user avatar
  • 3,792
11 votes
Accepted

Why does this Fourier transform not match the formula?

I think the confusion is between frequency in cycles per second or Hz and frequency in radians per second. In the page you link to the frequency is in Hz. Thus to match this convention the ...
user avatar
  • 14.7k
10 votes

How can I apply a function only to even-index elements of a list?

You can use the new ApplyTo: A = {1, 2, 3, 4, 5}; Dd[P_] := P + 1 A[[2 ;; ;; 2]] //= Dd; A (* {1, 3, 3, 5, 5} *)
user avatar
  • 35.6k
9 votes

Find shortest distance between two functions

Assuming that you mean the shortest distance between their graphs, the following does the job. ...
user avatar
  • 16.7k
9 votes
Accepted

How to use PlusMinus properly?

Per the documentation, you could define the function for PlusMinus: ...
user avatar
8 votes

How can I apply a function only to even-index elements of a list?

alist = {1, 2, 3, 4, 5} Using MapIndexed: ...
user avatar
  • 14.9k
8 votes

How can I use variables instead of slots in DeleteCases?

g[{a_, b_, c_}] := a + 2 b + c == 0 Using the operator form: DeleteCases[x_ /; g[x]][tuples]
user avatar
  • 14.9k
8 votes

How can I use variables instead of slots in DeleteCases?

Perhaps (Thanks to comment/correction @BenIzd ) DeleteCases[tuples, _?(Apply@Function[{a, b, c}, a + 2 b + c == 0])] is what you are looking for?
user avatar
6 votes
Accepted

While inside a function body does not work as expected

You may wish to disambiguate your description as it seems you're creating rational functions made up of polynomials. Below I modularized CreateDiscontinuityPoly ...
user avatar
  • 1,084
6 votes

How to simplify function with Abs?

Try this: Refine[Simplify[mylist], Assumptions -> x \[Element] Reals]
user avatar
6 votes

How can I apply a function only to even-index elements of a list?

Using Position and Map: ...
user avatar
6 votes

How can I apply a function only to even-index elements of a list?

SubsetMap[dd, arr, 2 ;; -1 ;; 2] (* {1, 3, 3, 5, 5} *) where: arr = {1, 2, 3, 4, 5}; dd[p_] := p + 1 Just for fun ...
user avatar
  • 10.3k
6 votes
Accepted

How to simplify function with Abs?

PiecewiseExpand does it. Edit and // ComplexExpand // Simplify does it ...
user avatar
  • 15.2k
6 votes

Why Mathematica does not return explicit output

You need to be careful about the precedence of each operation. Here's your original: A = ({{a11, a12}, {a21, a22}}) // Transpose[A] // MatrixForm Here is how the ...
user avatar
  • 3,792
6 votes
Accepted

Introduce formal symbols indexed by natural numbers

It is often useful to avoid Subscript, Superscript, and Subsuperscript and instead to just ...
user avatar
  • 120k
5 votes

How to simplify function with Abs?

Here's the ComplexityFunction way I referred to in my comment just to illustrate the alternative: ...
user avatar
  • 213k
5 votes

Find shortest distance between two functions

Assuming that you mean by "shortest distance" the x value and y values where both functions differ by a minimal amount. In this case the distance is given by the difference of the two ...
user avatar
  • 24.3k
5 votes
Accepted

Classifying elements, by the value of a fixed function, using Replace

L = Table[ConstantArray[1, RandomInteger[999]], 100000]; m = Replace[L, {x_List :> Quotient[Length@x, 100]}, {1}]; $$\{7,2,8,8,6,5,1,5,2,1,1,3,6,7,2,4,7,2,1,8,...
user avatar
  • 14.9k
5 votes
Accepted

Replacement, PatternTest, Module related Question

The reason your attempt fails is that at the time the Function is applied to its arguments, m has not yet been replaced by ...
user avatar
  • 23.4k
5 votes
Accepted

Tropical Operation Conversions: Multiple Operations

I assume that you want to replace Addition by "Max" and Multiplication by addition. It is not clear how a negative term should be treated. For the time being I assume that it will be ...
user avatar
  • 24.3k
4 votes
Accepted

Module returns multiple functions

The correct syntax is: prep[p1_, p2_] := Module[{}, f1[x_, y_] := (p1 + p2)*x + y; f2[x_, y_] := (p1 - p2)*x - y; {f1, f2}]; Then: ...
user avatar
  • 24.3k
4 votes
Accepted

How to get a function from a string?

Welcome to the community. With little generalization (be applied to any variable name), Here is how you can achieve your goal: Since Function has ...
user avatar
  • 5,089
4 votes

Tropical Operation Conversions: Multiple Operations

I'm not entirely sure if this is what you're looking for, but it seems you would just need to replace your x_ with x__ ...
user avatar
3 votes
Accepted

RunProcess : Save directly to Mathematica Variable

It might be possible to do what you say, if myprogram.exe can output the image data directly to stdout. But I wouldn't lose any sleep over having to create a ...
user avatar
  • 62.7k
3 votes

Generating a list of pure variables

A variation on J.M.'s approach using PadRight: ...
user avatar
  • 349k
3 votes

Counting negative values in list

Another one: Total@Boole@Negative@data
user avatar
  • 4,888
3 votes

Find global maximum of InterpolatingFunction in interval but not maximum value

Here is an example. data = Table[{x, Exp[x]*Sin[2*x] + 1}, {x, 0, 10, 0.2}]; ListPlot[data, PlotRange -> All] ...
user avatar
  • 16.7k

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