Questions tagged [map]

Questions about applying functions or operators to expressions, especially constructs that take advantage of Map (/@) functionality.

Useful Links:

411 questions
16
votes
3 answers

Mapping a pure function with multiple slots

Here is a pure function with multiple slots: (#1^2 + #2^2)&[3, 4] 25 But how can I map that pure function over lists of values? For example, say I want to map (#1^2 + #2^2)& over x = {1, 2, 4} and y = {3, 4, 6}. I have tried the following…
yanfyon
  • 594
  • 4
  • 15
11
votes
3 answers

Nested Map and Apply

There are some other questions on this topic but I could not get an answer from reading them. What I want to do is use Apply on some of the arguments of a function, h, and then Map on another argument. Here is what I attempted: Map[Apply[{h[#, ##]}…
BeauGeste
  • 2,815
  • 2
  • 29
  • 32
10
votes
2 answers

Using Map with If

I have an If statement I need to carry out where the result should be a single number for each time the if is executed. What I have at the moment returns a list for each time the If is executed. I specifically do not want to use a Do loop so is…
lara
  • 1,028
  • 7
  • 17
9
votes
3 answers

Mathematica periodic moving map

I am pleased to have MovingMap in Mathematica 10. But, today, I encountered the problem that needs MovingMap with a periodic boundary condition. To be specific, Consider the following example. MovingMap[ f, Range[3], {2} ] will gives the result…
Sungmin
  • 2,285
  • 15
  • 23
8
votes
3 answers

Map a function that takes arguments in different levels of a list

I would like to map a function that takes as an argument a list in a list of lists and an element of the list of lists. So for example, this is my list of lists: {{4,1}, {3,1,1}, {2,2,1}} I would like to map the function to the list of lists…
Mavatanet
  • 141
  • 1
7
votes
1 answer

grab one side of an equation

Is there a simple way to grab or reference one side of an equation? Minimal example of what I mean: eq = x^2==3x (*Pseudo Code*) in: Grab_lefthandside(eq) out: x^2
6
votes
3 answers

Unexpected behavior with Map

Using Map, one can apply a function f to the elements of a list: Clear[f]; Map[f,Range[10]] (*{f[1], f[2], f[3], f[4], f[5], f[6], f[7], f[8], f[9], f[10]}*) But the command does not seem to work if any modification is applied to f. For…
Whelp
  • 1,715
  • 10
  • 21
5
votes
2 answers

Can I exit a Map over a list of data pairs?

I've written a function, which I intended to Map over lists of some 8,000 element pairs. I created the "toy" code below to illustrate my problem. yld = 0.0742; pVal = 10000; pVal2 = 10000; dataPairs = {{a, 0.0027}, {b, 0.0027}, {c, 0.0027}, {d,…
Jagra
  • 14,343
  • 1
  • 39
  • 81
5
votes
1 answer

What's the difference between @ and /@?

The @ and /@ functions do the same thing: Factorial @ List[1, 2, 3, 4, 5, 6] {1, 2, 6, 24, 120, 720} Factorial /@ List[1, 2, 3, 4, 5, 6] {1, 2, 6, 24, 120, 720} What is the / for? I've looked all over and can't find any explanation for…
Dean Schulze
  • 243
  • 1
  • 6
4
votes
1 answer

Apply Max to each element of a list

I have a list a = {1, 8, 0, 6, 5, 3, 5, 2, 2, 5} I want to generate a new list whose elements are the same of a if it's bigger than 5, or 5 elsewhere. I managed to achieve this using Map and a pure function doing Map[(Max[#, 5]) &, a] but this…
Luca
  • 383
  • 1
  • 8
3
votes
2 answers

Partial application of MapThread

Suppose that I have f[a_, b_, x_] := ... I'd like to create a list of n pure functions {f[1, 4, #]&, f[2, 5, #]&, f[3, 6, #]&, ...} from two lists of length n like as = {1, 2, 3, ...} bs = {4, 5, 6, ...} What can I do? Given g[a_, b_] = ..., I…
Taiki
  • 5,259
  • 26
  • 34
3
votes
3 answers

Dynamic application of several polynomials

I know how to get the 'resulting image' (y) from the application of a certain function (f) (here represented as the coefficients of a polynomial) over a certain interval (x): x = Range[27000]/27001.; f = {25.62, -38.43, 21.81}/9; y =…
3
votes
3 answers

Map function over two lists

How to map a function over two lists, first one and than the other? For example, assuming I have two lists {a,b,c} and {d,e,f}: [#1 + #2] & /@ {{a,b,c},{d,e,f}} That maps the expression simultaneously, but I want a result looking…
M.B.
  • 193
  • 5
3
votes
1 answer

Im function won't distribute over a sum

When I take the imaginary part of a complex number times a function, I get the answer I was expecting, Refine[Im[(1+I) Cos[x], Element[x,Reals]] -> Cos[x] but if I include a sum, Refine[Im[(1 + I) Cos[x] + (1 + I) Sin[x]], Element[x, Reals]] ->…
Rodney Price
  • 283
  • 1
  • 7
3
votes
0 answers

Remove minus-signs from list

I have a list that is of the following form {-x,y,-z,a} I want this set to become this: {x,y,z,a} I tried the following: {-x,y,-z,a}/.{Minus->Plus} But with no success. Functions like Abs also don't work, since x,y,z,a are not defined.
Jasper
  • 131
  • 4
1
2 3