Skip to main content
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: ...
Henrik Schumacher's user avatar
14 votes

Threading arguments from lists of different size

This can be achieved with the new function Threaded (introduced in V13.1): ...
Sjoerd Smit's user avatar
  • 24.8k
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", ...
lericr's user avatar
  • 34.1k
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"]. <...
cvgmt's user avatar
  • 84.1k
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 ...
Syed's user avatar
  • 59.5k
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]}
AsukaMinato's user avatar
  • 10.4k
7 votes
Accepted

Nested lamdas: MapThreading a MapAt lambda

MapThread[MapAt[z \[Function] z/#2, #1, {All, 2}] &, {r`data, r`divs}] or ...
kglr's user avatar
  • 401k
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 ...
lericr's user avatar
  • 34.1k
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}] ...
cvgmt's user avatar
  • 84.1k
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]*)
Ulrich Neumann's user avatar
7 votes

How to Thread lists elementwise with the If function?

Inner is more suitable for this task then Thread. ...
cvgmt's user avatar
  • 84.1k
6 votes

Sum over two independent variables

You can modify the ranges as needed. ...
Syed's user avatar
  • 59.5k
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] ...
kglr's user avatar
  • 401k
6 votes
Accepted

Thread Matrices, like image channels

Thread/@Thread[{matA,matB}]==MapThread[List,{matA,matB},2]
user1066's user avatar
  • 22.7k
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]] ...
kglr's user avatar
  • 401k
6 votes

Thread map to 2 lists of inputs, including the nondiagonal terms

...
Roman's user avatar
  • 49.8k
6 votes
Accepted

Plotting set of functions with individual regionfunctions using PlotLegends

...
Syed's user avatar
  • 59.5k
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? ...
Syed's user avatar
  • 59.5k
5 votes

How to change the plot legends while mapping a plot command

Using MapThread: ...
Syed's user avatar
  • 59.5k
5 votes
Accepted

Generating a Table with two fixed variable and varying the third variable

...
Syed's user avatar
  • 59.5k
5 votes
Accepted

How to Vertically Stack Multiple Plots with Custom Color Functions and Opacity in Mathematica?

Keeping all your definitions, ...
Syed's user avatar
  • 59.5k
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 ...
m_goldberg's user avatar
  • 108k
4 votes

Thread Matrices, like image channels

You can also use Flatten: matC = Flatten[{matA, matB}, {{2}, {3}}] MatrixForm[matC, TableDirections -> {Column, Row, Row}] ...
kglr's user avatar
  • 401k
4 votes

How to Thread lists elementwise with the If function?

Just another way using MapApply: ...
E. Chan-López's user avatar
4 votes

Plotting set of functions with individual regionfunctions using PlotLegends

You can also use funs and regfun to construct ConditionalExpressions and ...
kglr's user avatar
  • 401k
4 votes

Threading arguments from lists of different size

Another way to do this using Table: ...
E. Chan-López's user avatar
4 votes
Accepted

Why does my Thread from Alphabet to morseAlphabet not work?

It seems OP has a definition like this: ...
Anton Antonov's user avatar
4 votes
Accepted

Convert list of variables to list of parametrized functions

...
eldo's user avatar
  • 83.1k
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. ...
azerbajdzan's user avatar
  • 25.1k
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. ...
Bob Hanlon's user avatar
  • 163k

Only top scored, non community-wiki answers of a minimum length are eligible