Questions tagged [slot]
The slot tag has no usage guidance.
55
questions
0
votes
0
answers
46
views
Trouble using list of slot variables?
When I run this code:
...
1
vote
0
answers
62
views
get the first from a list using slots [closed]
Problem. I work with a list and want to get the first element. For specific reasons I want to use # in combination with Map
For example
...
2
votes
0
answers
61
views
Is there a way to refer to the value of another key in the same association?
I have an association like below and want to know how to properly phrase the value for winner. in this example, the answer should be "a".
...
1
vote
2
answers
77
views
Table doesn't work with Slot [closed]
Using Mathematica, I was trying to get {#1,#2,#3,#4,#5}, using Table[#n, {n, 1, 5}] Instead I only got {#n, #n, #n, #n, #n} How can I get {#1,#2,#3,#4,#5},
6
votes
3
answers
307
views
Apply pattern using a Slot (#) to each list element using a second slot
I am trying to find a neat way of applying an operation to each list element, but do not know how to properly use multiple slots or whether it is actually possible to solve this with multiple slots.
I ...
3
votes
1
answer
155
views
How to replace a multiple iterator Table to speed up computation
I need to create an array of data which resembles to something like this
Table[{i, Sin[j^2*i]}, {j, 2000}, {i, 0., Pi, Pi/10000.}]
where each "row" of ...
0
votes
1
answer
110
views
Defining a general function f with slot-holder arguments #1, #2
I am trying to get a general function $f$ accept slot-holder arguments #1, #2, where the actual arguments are lists {a1, a2,...} and {b1, b2,....}. I thought that this would involve some combination ...
0
votes
1
answer
96
views
How to use map and slot effectively?
I want to change my code from :
f[n_, x_] := n Sin[x ]
Table[{x, f[0, x], f[1, x], f[2, x], f[3, x]}, {x, -\[Pi], \[Pi],1.0}] // Chop
with OUTPUT :
...
2
votes
1
answer
91
views
Activating part without resolving [[1]]
I'll try to make this question more clear in a little while. In the mean time, I'll ask directly the question which motivated it:
Latin Square from submatrix
Original Question
I want, for instance, ...
4
votes
1
answer
90
views
Defnining a function with a parameter which is not a slot but a constant [closed]
One convenient way to define a function is
f[S,x_]:= 3
f[G,x_]:= 7
where the first parameter is not a slot but a constant. This way of constructing functions is ...
8
votes
1
answer
313
views
How to supply argument to pure function when slot is already defined?
Here's an example of a pure function:
3^# > 100 &
I can supply any value I please to the function, by placing that value after the prefix. E.g.:
...
0
votes
1
answer
62
views
Slot in the code
I am given the following code in my notes:
...
5
votes
2
answers
165
views
bind specific 'Slots' to specific 'Map'
Is it possible to construct a pure function using multiple slots, with the following concept :
Binding specific slot to specific apply or map
For example :
In this example,
To ...
1
vote
1
answer
66
views
Apply function using level
The following use of Level is documented, without any example.
Let's try some simple codes :
...
4
votes
0
answers
68
views
Cannot access ColorFunction in ListVectorDensityPlot
Working on a vector field, I'd like to use a ColorFunction dependent on both the vector direction and its norm. According to the documentation of ...
0
votes
0
answers
56
views
Using slot and application to variable length vector
I have a list of 2D coordinates with a maximum length of 3, e.g.
peakdatAB
{{1007.81, 8.64842}, {1008.38, 8.19264}}
I need to generate something like this
...
2
votes
3
answers
89
views
Multiple Calculations in a condition
I want to add and subtract 3 from a list.
pos = {82,84}
If[# > 3,
(# - 3) && (# + 3)] & /@ pos
the output I want:
...
5
votes
4
answers
367
views
When applying (@@) a function to a list of potential arguments, how can Slot be used to take the last argument?
I wouldn't be surprised if the title question is confusing, so I'll try to elaborate by way of example.
Consider the list
...
7
votes
3
answers
487
views
What is the difference between a variable and a "slot variable"?
Investigating Function[] , I found:
What is the difference between using a variable (in the case, $u$) and a "slot variable"? It seems anything can be done ...
1
vote
0
answers
83
views
Slot numbers, pure functions [closed]
For the first line of code my function works fine on the list, but when trying to use Map I just keep getting an error (Function::slotn) basically saying there are not enough arguments for it to work, ...
1
vote
1
answer
124
views
Using # and ## in same statement to represent different levels
I am trying to write some codes to judge if each row of a matrix contains any negative numbers. For example mat = {{1, 2, 3}, {-1, 2, 3}, {0, 2, 3}}, and ...
0
votes
1
answer
145
views
What is the first slot value in this expression?
I would like to know what is the first slot value in the following expression
...
5
votes
2
answers
119
views
Using the Range function with the Slot (#) function
I am writing a code to display longitudinal waves.
I started with the following, filling the slots using the Range function.
...
1
vote
0
answers
105
views
Is there a good reason why `Slot[]` is not an atomic expression?
Here's a good reason why I think it should be,
Map[ If[AtomQ@#, #->"is an atom", #->"not an atom"]&
, {"hello",Range@3, # &}
, {-1}
]
...
3
votes
1
answer
148
views
Help me with understanding root objects [duplicate]
I solved an polynomial equation of degree 20 and got root objects as solutions. I cannot understand how to match such output to any standard analytic form. After studying ...
0
votes
0
answers
36
views
Translate Mathematica Output to Latex type font [duplicate]
In solving the inequality $2d^2\ge -(2(1+d)+\frac{4d^3}{1-d})(d-1)$, Mathematica returns something using Slots and Functions:
...
0
votes
1
answer
201
views
Convert a piecewise definition of a single impulse into an impulse train
NOTE: See update at end of question
I have a function smoothstep (based on the derivative of a smoothstep function) that gives a single impulse as follows:
...
16
votes
1
answer
973
views
Meaning of ## #
While looking for an answer to a different problem, I came across the following example:
In[1]:= Array[Plus[##] &, {2,2}]
Out[1]= {{2,3},{3,4}}
Having read ...
0
votes
1
answer
90
views
How I can get only second part of relation?
How I can get only the second part of this relation?
I want to get Image of function where R is a relation and ...
4
votes
2
answers
361
views
Drop 1st element of {#a, #b, #c} &
I pass the following to a function:
{#a, #b, #c} &
These are keys that are used in a list of associations.
There are instances where I want to pass only the ...
4
votes
1
answer
68
views
Combination of Scan[] and MapIndexed[]. Using an expression with slots corresponding to different functions [duplicate]
If I want to use slots corresponding to different function, how can I dod that. For example:
Scan[MapIndexed[(#1+#2)*#3&,{"a","b","c"}],Range[5]]
where I ...
0
votes
2
answers
308
views
Mapping slots over lists
In the meantime I'm accustomed to write special character orgies like D[%,#]&/@L (to quickly fish out the coefficients of the last input with respect to ...
9
votes
2
answers
297
views
Applying Function with SlotSequence and Lists
I would like to apply a function to a list of lists, while using each of the 2 elements of the list in a SlotSequence in two different places in the function.
What I am working with is
...
3
votes
2
answers
1k
views
explanation of #1 and #2 [duplicate]
EDIT: This was marked as a possible duplicate. While the referenced other question does talk about slots, my question is more about how to understand how multiple slots (#1 and #2) work. Also, my ...
3
votes
0
answers
45
views
Missing values vanish from expressions with DateObject and slot-lookup?
Missing value vanishes when adding or subtracting DateObject but only when slot-lookup is used, in an Association query:
Given
...
2
votes
2
answers
135
views
slot assignment to a local variable
Let me start with an example:
data = Partition[RandomInteger[50, 40], 3];
s = {10, 50};
I'd like to choose the first element of each sublist subject to the ...
0
votes
0
answers
49
views
Pure function slot delivery [duplicate]
Another novice problem encountered. I am going to need a cardiology surgery. :(
For a simple example,
a = #1 &;
b = #2 &;
f = a^2 + b^2;
f
results in
<...
4
votes
0
answers
53
views
Bug with LinearRecurrence and Slot/SlotSequence?
The code below runs without any error:
LinearRecurrence[{##}, {1}, 5]
Each term is the previous term squared, times the index of the previous term.
If the ...
0
votes
0
answers
206
views
The order of evaluations with nested slots [duplicate]
I tried to join a series of evaluations with nested slots as follows:
#^2 & /@ #^2 & /@ Range[10]
However, the results were somewhat different from what ...
1
vote
0
answers
123
views
What Does Slot Mean In Root Output and How To Translate It To Code? [duplicate]
I have the notebook below which produces the correct numerical output but the CForm function doesn't appear as though it is working correctly (or I don't know how ...
0
votes
0
answers
35
views
Understanding solution with slots [duplicate]
I am trying to find eigenvalues of a matrix. It has two symbols $k_1$ and $k_2$. I get this solution from mathematica
Reading the doucmentation, I know # is a placeholder, much like an input to an ...
0
votes
1
answer
127
views
How to generate a series of iterable slots in a template notebook?
How can I generate a seires of iterable slots in template notebook I can later loop over and assign values to? For example:
I could generate this manually by typing out each one. However, it gets ...
3
votes
2
answers
299
views
Application of # for the $n^{th}$ derivative
Let's say that I have
x^2+x
Is there a way to map $x$ to the first derivative of a function and $x^2$ to the second derivative of the same function? According to ...
1
vote
0
answers
97
views
Applying slots, one after another for a list [closed]
For this function:
Fun[x_] := 3 x^3 + 4 x^2 - 2 x - 1
I apply Map:
D[Fun[x], {x, #}] & /@ Range@3
and I get this ...
1
vote
1
answer
156
views
Explanation required for the Slot function
I have been trying to understand the following function
...
0
votes
0
answers
28
views
Slot representing the key in Association? [duplicate]
Is there a slot representation of the Key in an Association?
For instance, I would like to do same transformation with an Association:
...
7
votes
1
answer
228
views
Writing code which generates a function to append many columns to a dataset
I love datasets in Mathematica. Say I have one that looks like this:
...
0
votes
1
answer
206
views
Generating a function with named slots
Say I have an association:
a = <|"a" -> "albatross", "b" -> "barbecue", "c" -> "champagne"|>
And say I want a function with named slots to ...
12
votes
2
answers
421
views
Query datasets with "variable" named slots
I want to query a Dataset object, e.g. select some entries using
...
42
votes
0
answers
829
views
Front end goes wild with named slots
Bug introduced in 10 and fixed in 12.1
Assume the following simple expression
{#"Test"}&
Now go in front of the #...