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

learn more… | top users | synonyms

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

Map vs listable [duplicate]

What's the difference between setting a function's attribute as Listable and using Map? I understand that ...
1
vote
1answer
59 views

Plotting Invariant Manifolds of the Henon Map

Given the following map: \begin{align} & x_{n+1}=-y_n+2x_n^2 \\ & y_{n+1}=\beta x_n \end{align} for $β \in (0,1)$, $x_n \in \mathbb{R}, y_n \in \mathbb{R}$ (which is a one parameter version ...
0
votes
1answer
42 views

Applying multiple functions to a single column in a table

I've seen similar questions, but I'm having trouble applying solutions found there to my situation. My sorting function: ...
3
votes
2answers
68 views

Calculate Cumulative Mean and Standard Deviation of a list without FOR loops [duplicate]

I have a simple list mylist={x_1,x_2,...,x_N};. Now I want to map a function over this list, e.g. the Mean and StandardDeviation functions, so that it will give me ...
3
votes
2answers
150 views

How to plot coordinates with different colors on a map?

How can I plot different sets of coordinates with different colors? For example, the two maps below would be merged into one map, with two colors. I'm using the commands below to create the maps ...
3
votes
0answers
52 views

Remove minus-signs from list [closed]

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: ...
2
votes
1answer
58 views

Pairing values with their indexes for MapThread

Several operations require you to map over a list of values and to know the index of each value as you process it. To accomplish this, my current somewhat ugly solution uses MapThread: ...
3
votes
0answers
35 views

Custom iterable objects

I understand that to create objects with custom behavior with respect to existing code one uses upvalues. However, I'm at loss when it comes to guess what interface is expected from objects fed to ...
1
vote
1answer
67 views
1
vote
0answers
52 views

A kind of function optimization problem [duplicate]

I have the following problem. Out of a calculation I got the four functions shown at the end of the post. These functions depends on many variables, qk, pk etc (all of them are actually scalar ...
5
votes
5answers
488 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: ...
1
vote
2answers
52 views

Importing data, then plotting ListPlot. What's the most efficient way to write a code?

It should be a boring question to ask for someone, but this is very basic need which I haven't resolved by myself. I know I can use MapThread and pure function to make it short and beautiful, but even ...
3
votes
3answers
116 views

how to map a function on a variable list

The following is just an example that captures what I want to do (more on it at the bottom). I'm trying to do something that can be paraphrased as follows: I have a global list, say ...
4
votes
1answer
81 views
1
vote
2answers
46 views

using Map to apply 2 lists to the LCM function - help [duplicate]

I have 2 lists of numbers and I want to quickly compute the array of answers to the LCM function for the 2 lists and a 3rd static number. I tried the following ...
3
votes
1answer
93 views

Map if-function on a list

I need to convert a battery charging mechanism from Excel into Mathematica. This Excel function is about deciding if the charge/decharge rate is positive, then multiply with efficiency factor, ...
0
votes
1answer
63 views

Fastest way to make division between a number and elements in a list [duplicate]

I have a list y={{a,b},{c,d},...} of dimension {10^5, 2}, and number x. I want to divide only the second part of each element of the list by x, and have as result a new list {{a,b/x},{c,d/x},...}. ...
10
votes
8answers
824 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: ...
3
votes
0answers
67 views
3
votes
0answers
54 views

Monitor CUDA function

Is there a way to monitor CUDA function without bringing much performance reduction. For example, Map can be monitored by ...
3
votes
3answers
117 views

Mapping at arbitrary nested list [duplicate]

This is a candidate for a duplicate (probably from the documentation) but I've ironically failed to find the direct analog so far. I have an arbitrary nested list, say: ...
0
votes
2answers
103 views

How to map the second highest value in each row of a matrix

I have a matrix with three or more columns called mat. I would like to map the second highest value in each row of mat into its ...
9
votes
1answer
149 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 ...
0
votes
0answers
43 views

how to use a tree as a key to construct a table of key values

I have an interesting problem that I was able to summarize in the form of trees, sets, and key value pairs. I have the following sets of keys and values \begin{equation} \begin{aligned} k_0 &= ...
1
vote
2answers
62 views

Creating authomatically inequalities/equations from a list of polynomials

I am trying to learn how to make automatically from a list of polynomials (or an arbitrary collection of algebraic expression) a list of inequalities/equalities (those will later serve as constraints ...
12
votes
1answer
282 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 ...
1
vote
0answers
50 views

Mapping over two indices with a condition

How can I use Map over two indices with a condition? I am trying to calculate second derivative of an eigenvalue, $\lambda_i(x)$, of $n \times n$ matrix $M(x)$ ...
2
votes
2answers
90 views

Issue with pure function when mapping dynamic content within graphics scope

What I am trying to achieve can be described using following code: vector = {{0, 0}, {1, 0}}; Graphics[Circle[#, 1] & /@ vector] In the above, a pure ...
12
votes
3answers
516 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 ...
9
votes
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. ...
2
votes
3answers
101 views

Importing and saving .csv files as variables with the original filebasenames

I have a modest number of .csv files that I want to import into mathematica. I would like to save their contents as their filebasename for use throughout my notebook, but I am running into errors as ...
10
votes
4answers
338 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 ...
8
votes
2answers
110 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 ...
0
votes
1answer
64 views

How to put a levelspec in operator form? [closed]

All variable argument functions need Function wrapped around them in operator form, but is there any other way to achieve this: ...
3
votes
1answer
97 views

Using Map multiple times in one command

Is there a way to reproduce the effect of Table[i ** j, {i, list1}, {j, list2}] using Map instead of Table? Specifically, I want to write something along the ...
2
votes
2answers
84 views

Perform calculation on several sublists using Map

I am trying to perform a calculation on a list containing sublists. More exact: The x-axis values are time data, progressing from zero, the y-axis data are data points, which I want to normalize. I ...
3
votes
3answers
636 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
115 views

How to map an inequality to a list?

vars = Table[Subscript[a, j], {j, 5}] We can do the total Total[vars] and produce ...
5
votes
3answers
327 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, ...
2
votes
1answer
121 views

Use Map with multiple arguments over a nested list

I noticed there are a few similar questions to mine on here, but I couldn't figure out how to accomplish this mapping. I have sets of data I want to plot, which represent intensity and frames, and I ...
3
votes
1answer
124 views

Map an Argument to a list of functions

I want to "map" an argument to a list of functions. Here is the concrete Problem. I generate a list "Messungfit" of functions: ...
3
votes
2answers
82 views

Faster use of Condition for a large array (see the example)

Here is the example/problem. I have a array of $n$ random number. n = 2000; p = RandomReal[{0, 9}, n]; I have to create a $n\times n$ sparse matrix with ...
7
votes
2answers
210 views

Speed and the MapThread function

Can anyone help explain why MapThread is so slow in this simple case? ...
1
vote
1answer
72 views

How-to implement iteration over a result of an iteration in a functional way

I have a pure function f:= #1 * #2 * #3 &; Which I can invoke in a following way: f[#,2,3]& /@ {1,2,3} Which ...
4
votes
1answer
241 views

Applying function to cartesian product of two lists

I have two lists X = {1, 2, 3}; Y = {5, 6, 7, 8}; I want to apply function g[x,y_,z_] to all pairs from X*Y, so I need to ...
3
votes
1answer
142 views

Parallel Apply on a deeply nested expression

I have a deeply nested expression, i.e. something like {{{{...}..}..}..}, and I'd like to use Apply in a parallel fashion, e.g. ...
4
votes
2answers
189 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 ...
17
votes
2answers
578 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 ...