WOLFRAM COMMUNITY
Connect with users of Wolfram technologies to learn, solve problems and share ideas
Join
Sign In
Dashboard
Groups
People
Message Boards
Answer
(
Unmark
)
Mark as an Answer
WOLFRAM COMMUNITY
Dashboard
Groups
People
1
|
10216 Views
|
3 Replies
|
5 Total Likes
View groups...
Follow this post
Share
Share this post:
GROUPS:
Mathematica
Wolfram Language
Symbolic Computations
Map/Apply over a list with optional arguments
Casper YC
Casper YC, Kent
Posted
11 years ago
Hello,
I have a list
x = {a, b, c, d}
and can be mapped to the function using
Map[f, x]
Say if the function takes two arguments, is this possible to get
{f[arg1,a], f[arg1,b], f[arg1,c], f[arg1,d]}
many thanks!
POSTED BY:
Casper YC
Reply
|
Flag
3 Replies
Sort By:
Replies
Likes
Recent
0
Bruce Miller
Bruce Miller, Wolfram Research
Posted
11 years ago
Thread works, too.
In[1]:= x = {a, b, c, d};
In[2]:= Thread[ f[arg1, x] ]
Out[2]= {f[arg1, a], f[arg1, b], f[arg1, c], f[arg1, d]}
http://reference.wolfram.com/mathematica/ref/Thread.html
POSTED BY:
Bruce Miller
Reply
|
Flag
2
Daniel Lichtblau
Daniel Lichtblau, Wolfram Research
Posted
11 years ago
The pure function approach is usually best. If for some reason you want to avoid that, could curry the thing as below.
f[arg_][x_] := f[arg,x]
Now you can do
Map[f[arg1], list]
POSTED BY:
Daniel Lichtblau
Reply
|
Flag
2
Terrence Honan
Terrence Honan, Blinn College
Posted
11 years ago
f[arg1,#]&/@x
Here I used an anonymous function. Note that Map[f,x] is the same as:
f/@x
POSTED BY:
Terrence Honan
Reply
|
Flag
Reply to this discussion
in reply to
Add Notebook
Community posts can be styled and formatted using the
Markdown syntax
.
Tag limit exceeded
Note: Only the first five people you tag will receive an email notification; the other tagged names will appear as links to their profiles.
Publish anyway
Cancel
Reply Preview
Attachments
Remove
Add a file to this post
Follow this discussion
or
Discard
Group Abstract
Be respectful. Review our
Community Guidelines
to understand your role and responsibilities.
Community Terms of Use
Feedback