# Tagged Questions

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

12answers
2k 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 ...
3answers
2k 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: ...
2answers
2k views

### Scan vs. Map vs. Apply

I cannot understand the difference between Apply, Scan, and Map. I have tried to play with ...
2answers
623 views

### Can A Plot Be Overlayed With A Map?

Some brief, only slightly important background. I am doing a research project using the data from NASA's GRACE mission. I wrote a short Perl script to take two data files and find the change in ...
3answers
525 views

### Map a function of several arguments

I have three lists, e.g. list1 = {{a,b,...}}; list2 = {{1,2},{3,4},...}; list3 = {{x,y},{z,w},...}; and a function ...
1answer
284 views

### Mapping on leaves

Say I have some nested structure, such as {a,{{b,c},d,{e,{f,g}}}}, and I want to apply a function $q$ to each of the leaves; that is, I want the output to be ...
5answers
471 views

### Element-wise test on List elements

This question could sound pretty silly but I can't find a way to apply element -wise tests to a list. For example if I digit ...
4answers
410 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. ...
6answers
395 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: ...
8answers
849 views

### Best way to emulate MATLAB's bsxfun using Map and similar functions

Given a matrix, we want to subtract the mean of each column, from all entries in that column. So given this matrix: ...
8answers
632 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 ...
5answers
631 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 <...
3answers
950 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 ...
3answers
3k 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 ...
3answers
370 views

### Operate over list of pure functions

I have list of pure functions (All functions are InterpolatingFunction) i.e {{a, b}, {c, d}, {e, f}, ...} and I would like ...
1answer
152 views

### How to make a function to analyse a sentence?

I have two lists: grammarNonterminal = {{VP,{V,NP}},{NP,{D,N}},{S,{NP,VP}}} sentence = {{D,"the"},{N,"man"},{V,"hit"},{D,"the"},{N,"table"}} I want to make a ...
1answer
108 views

### MapAt with Replace(All) causing kernel crash

Bug introduced in 10.1 and fixed in 10.2 I wanted to roll a function that works like /. but only acts on the very first match it encounters. ...
5answers
276 views

### How to Map a function with HoldAll attribute

First of all, I'm not sure about the title of this question, so please correct me if there is any title more sensible than mine. The problem is the following: I have a function f that checks if a ...
3answers
336 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 ...
2answers
468 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 ...
2answers
112 views

### multiple maps to extract from association

I've got some code that has to extract a lot of information, including some statistics, from an association. There's a lot of repetition in my code and I'm hoping that there's some way to simplify it ...
5answers
655 views

...
2answers
636 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 ...
2answers
216 views

### Speed and the MapThread function

Can anyone help explain why MapThread is so slow in this simple case? ...
3answers
7k 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 ...
3answers
405 views

### Functional equivalent of a For loop referring to consecutive elements in a list

I have implemented this function which smooths the values in a list by, if it encounters a zero, replacing this entry by the average of its two neighbours (apart from the first and last values of the ...
3answers
232 views

### Mapping a function over the parts of a deeply nested Array

I have two tensors: tensorS = Array[Subscript[s, #1, #2, #3, #4] &, {2, 16, 16, 19}]; tensorR = Array[Subscript[r, #1, #2, #3] &, {2, 16, 19}]; ...
2answers
1k 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, ...
1answer
138 views

### Map vs listable [duplicate]

What's the difference between setting a function's attribute as Listable and using Map? I understand that ...
1answer
791 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: ...
2answers
522 views

### Apply function to every element of list regardless of depth

I want to apply a function to every element of a list without taking braces into account (depth level), but with the same form of output. Here is an example : ...
2answers
327 views

### 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. <...
2answers
161 views

### Is there a built-in function to map a list of heads to a list of data?

Assume that this built-in function is called func. What I want is func[{f,g},{a,b,c}] will return the following result: <...
2answers
266 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: ...
6answers
360 views

### Indexed Map Thread

I'm attempting to MapThread a function of two lists that requires the index of the list values. For example, MapThread[#1*i+#2*j&,{{a,b,c},{e,f,g}}] Where #1 ...
3answers
377 views

### how to concatenate a list of a list of strings

I have two lists of lists, La and Lb that I want to concatenate so that every element of a list n in La is concatenated with the corresponding element of list n in Lb. For example: La = {{P, O, O, O}...
2answers
130 views

### A problem with Compile and Map

There is a weird behavior of Compile that I do not understand. Consider the following example: ...
1answer
559 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 ...
2answers
166 views

### Indexed Thread on dataset and list

I currently have a dataset, and I would like to add a column based on another list. For example: ...
1answer
147 views

### Mapping over an association producing an unexpected result

The documentation for associations says that the keys of an association are transparent for many operations. Map is one such operation. However, I am confronted ...
1answer
172 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 ...
1answer
88 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: ...
1answer
122 views

### How can Map be given access to the keys of a Dataset?

Consider an example Dataset: ...
4answers
144 views

### Plot range of a 2-dimensional function as a function depending on one variable

I want to plot a function of 2 variables x and y, for discrete values of y, like: ...
2answers
194 views

### How to convert a list of 3D points to a list of distances?

How do I apply a function (this case EuclideanDistance) between element i and i+1 on a list ...
3answers
224 views

### How to map over inner keys of nested Associations?

Considering an association: <|"a" -> <|aa-> "asc", bb-> "asd", cc-> 0, ImageType -> "asd", dd-> "asd"|>|> How can I make the inner ...
1answer
194 views

### MovingMap maps to second level unexpectedly

I'm trying to build a financial indicator in mathematica. I import some historical data ...
1answer
604 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 ...
1answer
85 views

### Creating a list of unevaluated pure functions with Apply

Suppose I have a list list with length L and a function ...
1answer
291 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 ...