25
votes
Accepted
Metropolis-Hastings Algorithm - Significantly slower than Python
Here a bit of inspiration for you. The following code should be approximately as fast as your Python code.
Preparation:
...
14
votes
Threading arguments from lists of different size
This can be achieved with the new function Threaded (introduced in V13.1):
...
12
votes
Accepted
How to Thread lists elementwise with the If function?
Thread doesn't hold its arguments unevaluated. In
Thread[If[#1 > #2, 1, 0] &[list1, list2]]
the "body", ...
10
votes
Accepted
Adding shadows to spiric sections of a torus
My answer keep the mesh with the same shape.
Show all the parts and then use the ResourceFunction["DropShadow"].
<...
9
votes
Accepted
Threading arguments from lists of different size
Inner[F, list1, #, Sequence] & /@ list2
{F[x, a], F[y, b], F[x, c], F[y, d], F[x, e], F[y, f]}
Compare with the following that can be flattened later, if ...
9
votes
Threading arguments from lists of different size
Table[
Sequence @@ MapThread[F,{list1, j}],
{j, list2}
]
{F[x, a], F[y, b], F[x, c], F[y, d], F[x, e], F[y, f]}
7
votes
Accepted
Nested lamdas: MapThreading a MapAt lambda
MapThread[MapAt[z \[Function] z/#2, #1, {All, 2}] &, {r`data, r`divs}]
or
...
7
votes
Thread Matrices, like image channels
I personally like using the built in restructuring functions for things like this. Things like ArrayReshape, ArrayPad, Riffle, PadLeft/Right, etc. For this particular case, I think you could use ...
7
votes
Accepted
Sum over two independent variables
In Mathematica 13,we can just use sum
pts = {{0, -2}, {1, -4}, {2, -6}, {3, -8}, {4, -10}};
Sum[f @@ p, {p, pts}]
...
7
votes
Sum over two independent variables
Perhaps
Total@MapThread[F[#1, #2] &, {Range[0, 4], Range[-2, -10, -2]}]
(*F[0, -2] + F[1, -4] + F[2, -6] + F[3, -8] + F[4, -10]*)
7
votes
How to Thread lists elementwise with the If function?
Inner is more suitable for this task then Thread.
...
6
votes
6
votes
Sum over two independent variables
Inner[f, 0 ~ # ~ 4, -2 # @ 5]& @ Range
f[0, -2] + f[1, -4] + f[2, -6] + f[3, -8] + f[4, -10]
...
6
votes
Accepted
Thread Matrices, like image channels
Thread/@Thread[{matA,matB}]==MapThread[List,{matA,matB},2]
6
votes
Thread map to 2 lists of inputs, including the nondiagonal terms
a = {a1, a2, a3}; b = {b1, b2, b3};
Tuples[f[a, b]]
...
6
votes
6
votes
Accepted
5
votes
Accepted
Thread map to 2 lists of inputs, including the nondiagonal terms
Originally you were asking:
a = {a1, a2, a3};
b = {b1, b2, b3};
MapThread[f, {a, b}]
{f[a1, b1], f[a2, b2], f[a3, b3]}
How can I get a full list that I want?
...
5
votes
5
votes
Accepted
5
votes
Accepted
How to Vertically Stack Multiple Plots with Custom Color Functions and Opacity in Mathematica?
Keeping all your definitions,
...
4
votes
Nested lamdas: MapThreading a MapAt lambda
By using ReplacePart in place of any mapping function, there is no need to define any function, neither explicitly like your r`f ...
4
votes
Thread Matrices, like image channels
You can also use Flatten:
matC = Flatten[{matA, matB}, {{2}, {3}}]
MatrixForm[matC, TableDirections -> {Column, Row, Row}]
...
4
votes
4
votes
Plotting set of functions with individual regionfunctions using PlotLegends
You can also use funs and regfun to construct ConditionalExpressions and ...
4
votes
4
votes
Accepted
Why does my Thread from Alphabet to morseAlphabet not work?
It seems OP has a definition like this:
...
4
votes
Accepted
4
votes
Using MapThread with pure function and variable number of elements
No need to make list of each slot, use ## which is sequence of all slots/arguments.
...
4
votes
How to Vertically Stack Multiple Plots with Custom Color Functions and Opacity in Mathematica?
$Version
(* "14.1.0 for Mac OS X ARM (64-bit) (July 16, 2024)" *)
Clear["Global`*"]
Index your variables to facilitate their use.
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
mapthread × 33list-manipulation × 16
map × 8
plotting × 6
graphics × 3
functions × 3
legending × 3
matrix × 2
equation-solving × 1
performance-tuning × 1
function-construction × 1
graphics3d × 1
export × 1
programming × 1
evaluation × 1
replacement × 1
color × 1
regions × 1
syntax × 1
summation × 1
parallelization × 1
formatting × 1
geometry × 1
expression-manipulation × 1
labeling × 1