The tag has no wiki summary.

learn more… | top users | synonyms

27
votes
12answers
1k views

Map a function across a list conditionally

It seems that this is a really basic question, and I feel that the answer should be obvious to me. However, I am not seeing. Can you please help me? Thanks. Suppose I have a list of data ...
11
votes
4answers
379 views

What's fastest way of defining 10^5 down values?

I want to define isGood[___] = False; isGood[#] = True & /@ list where list is a list of several million integers. ...
9
votes
6answers
286 views

Using MapIndexed only at certain elements of a list

MapIndexed is a very handy built-in function. Suppose that I have the following list, called list: ...
8
votes
8answers
345 views

How to use Map inside MapThread?

Given this input lst1 = {{a, b, c}, {d, e, f}}; lst2 = {1, 2}; and the goal is to generate this output ...
8
votes
5answers
320 views

Span a function across several consecutive elements in a list

Suppose that I have a list called list. I would like to span an arbitrary function f across specified consecutive elements in ...
8
votes
2answers
302 views

Scan vs Map vs Apply

I cannot understand the difference between Apply, Scan, and Map. I have tried to play with ...
8
votes
3answers
217 views

finding anagrams

What I'm trying to find are the 4 letter words in the mathematica dictionary that have the most anagrams and the amount of anagrams these have each. But I can't seem to find all the 4 letter words in ...
7
votes
3answers
462 views

how to efficiently apply function to all pairs of a set (and collect the results)

To build a graph, I need to apply a function f[a_, b_] to all pairs of a list (3500 elements). The function itself returns a link ...
7
votes
2answers
288 views

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 ...
7
votes
1answer
96 views

Changing Values in an Association using Map

I am trying to change the value of one key in an association based on the value of another key in that association. So if my association starts as: ...
6
votes
2answers
339 views

Map a function over the columns of an M x N array

I have a $N \times M$ list of lists, or rather, a list of records and I want to map a function over its columns (e.g. find the mean temperature, age, etc.). Map ...
6
votes
3answers
543 views

Mapping a pure function with multiple slots [duplicate]

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 ...
6
votes
2answers
451 views

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, ...
6
votes
2answers
192 views

Variable scoping problem when mapping over delayed replacement

This is something that got me curious while I was playing around with Mathematica. Consider the following (contrived) example: ...
5
votes
1answer
339 views

nested use of Apply/Map/MapThread in pure functions

1. My main question I have a function with two argument slots. I wan't to apply this function to 2 lists with different length's. I thought in this solution: ...
5
votes
1answer
78 views

MapIndexed stops at levelspec 1 if only the index is passed?

If the function passed to MapIndexed references the first (or data) argument, the following performs as expected: ...
5
votes
1answer
106 views

How can I substitute something using only map?

For example, I have the equation x^2 + y^2 == x*y and I want to apply the rule y -> s*x I can do it easily by ...
4
votes
1answer
465 views

Why is there a huge performance gap using Map with more than 100 List entries

im using Map on a List like this: cube= {{1, 1, 1}, {1, 1, 2}, {1, 1, 3}, {1, 1, 4}, ... , {5, 5, 4}, {5, 5, 5}} Mapping the whole List with 125 entries takes ...
4
votes
1answer
86 views

Parallelize[Mapindexed[]], level={-1}? Sal Mangano's 《Cookbook》

It is easy to Parallelize[] Map[] & MapIndexed[], as having been shown in MMA9 Help for ParallelMap[] and Parallelize[]. For MapIndexed[], the default levelspec is {1}. However there are many ...
4
votes
2answers
126 views

Can one use Map during Expand?

Can one Map a simplifying function to the summands of an Expand before fully expanding the expression in question first? ...
4
votes
1answer
135 views

MapThread and Compile

After discovering that MapIndexed cannot be used with compile (see MapIndexed and Compile) I am now trying do implement similar functionality using a combination of ...
3
votes
4answers
327 views

How to apply a function of several arguments to a list?

I have a list of triplets: list = {{1, 3, 5}, {4, 5, 1}, {4, 9, 2}} How can I apply a function f to the last element of each triplet when f the last and ...
3
votes
3answers
2k views

Map w/ multiple arguments [duplicate]

Possible Duplicate: How do I use Map for a function with two arguments? If I have a function: F[x_,y_,z_]:=x*y*z and I want to call it with several ...
3
votes
4answers
136 views

Correct slot assignment when mapping from different lists using pure function

Given expr = u == a1 + a2 x + a3 y; and uRep = {u1, u2, u3}; xyRep = {{x1, y1}, {x2, y2}, {x3, y3}}; I'd like to generate ...
3
votes
3answers
98 views

Applying a function of several arguments to the rows of a matrix

I have a user-defined function which takes three vectors as input. Suppose that is like this: f[a_, b_, u_] := Total[a*Total[u]^b] Usually I have vectors for ...
3
votes
2answers
228 views

Mapping multiple functions over an array

I am looking for an elegant way to Map multiple functions over an array. My problem looks something like this: Consider a list of functions: ...
3
votes
1answer
183 views

MapThread Alternatives

I want to add two matrices, the first one containing a 2D vector at each position the other one a list of 2D vectors. The 2D vector from the first matrix should be added to each of the 2D vectors at ...
3
votes
3answers
161 views

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): ...
2
votes
4answers
267 views

another way to do this mapping of a two argument function

Sorry, I'm just starting to learn mathematica. I have the following two-argument function: h[{x_, y_}] := x ^ y When I do the following: ...
2
votes
2answers
142 views

Using DeleteCases and Map together

Given: list1 = {{"a",1},{"b",2},{"c",3}} I would like to delete any pair in list1 that does not have a first element that belongs to list2. Example 1: If ...
2
votes
2answers
322 views

Efficiently compute double sum

Is there a "Mathematica Way", like Map or Apply to compute the following double sum? $\sum_{i=1}^{N_1}\sum_{j=1}^{N_2} m_i n_j \, f(\tau_{i} \gamma_{j})$ I have already stored the lists ...
2
votes
1answer
77 views

Can I use Map here rather than Table?

I've got something that works, but it seems like it would be "nicer" if I didn't have to use Table (or For, etc.). I've got 3 Excel files, each with multiple sheets. Each file also has a sheet ...
2
votes
1answer
249 views

Using Thread or MapThread over multi-level, ragged lists [duplicate]

This may be a rather strange question. I will try to create a sort of minimal working example. Suppose that I have two lists, list1 and ...
2
votes
1answer
112 views

Can Map operations be compiled or otherwise sped up for large lists?

I'm performing a series of Map operations in the following script: ...
2
votes
2answers
117 views

Map 2 list to a function

Im playing around with CountryData and I want to pass it 2 lists as argument, listCountries = {...} and ...
2
votes
1answer
167 views

Issue with ListConvolve

I am a new Mathematica user, learning the intricacies of functional programming. I have issues withe applying a function over a moving list. My function seems to work and give correct results but it ...
2
votes
1answer
92 views

Loop in solving multiple matrix calculation

I am wondering is there a way to use loop, like Do, For, to rewrite the last line in the code. I tried to use ...
2
votes
1answer
78 views

Country borders and grids with CountryData plot?

I am coloring several countries in the manner of the following: ...
2
votes
0answers
103 views

Want explanation of when different looping constructs are appropriate [duplicate]

For example when would you use a Do loop over a For loop? For which tasks would you use Map, ...
1
vote
4answers
195 views

Unexpected result from Map [closed]

I'm using Mathematica 8.0. Is the following output a bug or do I miss something? f[a_] = 2 a; Map[f,1+x] gives $2+2x$ as expected, but ...
1
vote
1answer
183 views

Map a function conditional on elements at multiple relative positions in a list

I figure this question has many solutions, and if an answer already exists it would be nice just to be referred to it. I need a function that 'maps' over my list and produces a list of equal length ...
1
vote
2answers
183 views

How to apply function f for each time value t, to each pixel from image, resulting in t images

I have a 2D array of complex values and I want to apply a function to every entry of the array, for every timepoint t in a list. I know how to apply my function to one entry for every time t in a ...
1
vote
3answers
153 views

Distinguishing slots in a function mapping Position across a list

Suppose that I have a list myList that has more than one level. Here is an example of such a "data structure": ...
1
vote
1answer
120 views

MAP a business cycles model

There is a Business Cycles Map on Phaser 3.0 and I've trying to run it on Mathematica the last four days without succes. The equations are $$ x_1 = (1.0 - a s)x_1 + a \left[s m + g \left(\frac{s ...
1
vote
2answers
77 views

How to construct a new list made from a function that operates on two lists

I need to take two lists (each list contains the number of moles of a chemical). I have a function calledFraction that takes the each entry of the list and then calculates the mole fraction of ...
1
vote
2answers
188 views

Expectation over a list with nested-mapped expressions

I need expected values of a list where the random variable to take expectations over should be an input into expressions defined earlier. I suspect Set[] and SetDelayed[] tripped me. (Or Map and ...
1
vote
3answers
115 views

Placeholders for map inside a map

I have a list structured like list1 = {{"header1","header2","header3"}, {0,1,2}}; and I'm using a custom function to find the number of the column with a ...
1
vote
1answer
133 views

MapThread multiple functions onto multiple lists

I'm trying to learn the functional style which seems to prevail in Mathematica. I'm having trouble accomplishing the following: Let's say I have multiple lists of arbitrary data (using two lists ...
1
vote
1answer
58 views

alignment of plots [closed]

I want to align my plots like I did with Gird[]. But you cracks here are using these short forms all the time. So, is there a way to achive this result in a better ...
0
votes
2answers
92 views

Apply Eigenvalues to a list of matrices

I would like to apply Eigenvalues[] to a list of matrices as in the following ...