Threaded[list]
is an object whose elements will automatically be threaded into the lowest level of an array when used in a listable operation such as Plus.
a+Threaded[b]
adds elements of an array b to elements of an array a at the lowest possible level.
a+Threaded[b,alev]
adds elements at level alev of a.
a+Threaded[b,blevalev]
adds elements at level alev in a to level blev in b.
f[a,Threaded[b,…]]
combines elements for a function f with the attribute Listable.
Threaded
Threaded[list]
is an object whose elements will automatically be threaded into the lowest level of an array when used in a listable operation such as Plus.
a+Threaded[b]
adds elements of an array b to elements of an array a at the lowest possible level.
a+Threaded[b,alev]
adds elements at level alev of a.
a+Threaded[b,blevalev]
adds elements at level alev in a to level blev in b.
f[a,Threaded[b,…]]
combines elements for a function f with the attribute Listable.
Details
- In a+Threaded[b], the lowest-level dimensions of a must match the dimensions of b.
- For a function f with the Listable attribute, f[a,b] effectively applies f to the elements in arrays a and b, working from the uppermost level down. Using Threaded gives control over how the elements are combined in a.
- If a has dimensions {adim1,…,adimj} and b has dimensions {bdim1,…,bdimi}, then the levels correspond to dimensions as follows:
- In f[a,Threaded[b]], a and b should be rectangular arrays with ArrayDepth[a]≥ArrayDepth[b].
- Threaded[b] is equivalent to Threaded[b,1-ArrayDepth[b]] or to Threaded[b,-1-1]. »
- Threaded[b,alev] is equivalent to Threaded[b,1alev].
- f[a,Threaded[b,alev]] with alev<0 is equivalent to f[a,Threaded[b,ArrayDepth[a]+alev+1]].
- f[a,Threaded[b,alev]] with alev>0 is equivalent to Map[f[#,b]&,a,{alev-1}] .
- f[Threaded[a,alev], Threaded[b,blev]] gives a result with head Threaded if alev and blev have the same sign.
Examples
open all close allBasic Examples (1)
Add the pair {x,y} to each element in a list of pairs:
{{1, 2}, {3, 4}, {5, 6}} + Threaded[{x, y}]Without Threaded, adding a list of scalars to the list of pairs would add a scalar value to each pair:
{{1, 2}, {3, 4}, {5, 6}} + {x, y, z}Scope (7)
Create a rank-three array with dimensions {2,3,4}:
arr = Array[Subscript[a, ##]&, {2, 3, 4}]Add a 3×4 matrix to each of the two matrices in the array:
mat = (| | | | |
| - | -- | -- | -- |
| 1 | 2 | 3 | 4 |
| 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 |);arr + Threaded[mat]Create a rank-four array with dimensions {2,3,4,2}:
arr = Array[Subscript[a, ##]&, {2, 3, 4, 2}]Adding a 3×4 matrix at the deepest threading level will fail because 3×4 differs from 4×2:
mat = (| | | | |
| - | -- | -- | -- |
| 1 | 2 | 3 | 4 |
| 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 |);arr + Threaded[mat];
The matrix can be added at level 2 because the dimensions match:
arr + Threaded[mat, 2]Since the deepest array has rank 4, this is the same as threading at level -3:
% == arr + Threaded[mat, -3]Combining a scalar with a Threaded argument gives a Threaded result:
res = 2 * Threaded[{-1, 1}]res * {{a, b}, {c, d}}2 * (Threaded[{-1, 1}] * {{a, b}, {c, d}})When all of the arguments are Threaded objects, then the result is a single Threaded object:
Threaded[{-1, 1}] + Threaded[{{a, b}, {c, d}}]Compare using Threaded with different positive levels for an array with depth 4:
Table[Framed[(Array[a, {2, 2, 2, 2}] + Threaded[{x, y}, n])[[All, All, All, All, 1]]], {n, 4}]Compare using Threaded with different negative levels for an array with depth 4:
Table[Framed[(Array[a, {2, 2, 2, 2}] + Threaded[{x, y}, -n])[[All, All, All, All, 1]]], {n, 4}]Use Threaded with an arbitrary listable function:
SetAttributes[f, Listable];f[Threaded[{a, b}], {{1, 2}, {3, 4}}]Threaded arguments can appear in any order:
f[0, {-1, -2}, Threaded[{a, b}], {{1, 2}, {3, 4}}]Use Threaded with SparseArray objects:
m = SparseArray[{{1, 0, 2}, {0, 3, 0}}];
v = SparseArray[{4, 5, 0}];m + Threaded[v]MatrixForm[%]m * Threaded[v] // MatrixFormApplications (2)
Add a vector to each row of a matrix:
Threaded[{a, b, c}] + (| | | |
| - | - | - |
| 1 | 2 | 3 |
| 4 | 5 | 6 |) //MatrixFormAdd a vector to each column of a matrix:
{α, β} + (| | | |
| - | - | - |
| 1 | 2 | 3 |
| 4 | 5 | 6 |) //MatrixFormZero the red channel and double the blue channel in 3D image data:
data = ImageData[[image]] * Threaded[{0., 2., 1.}]Image3D[data]The same construct works for 2D image data:
Image[ImageData[[image]] * Threaded[{0., 2., 1.}]]Properties & Relations (8)
Threaded[y,…] stays unevaluated unless inside a wrapping head with the Listable attribute:
t = Threaded[{x, y}]plus[{{a, b}, {c, d}, {e, f}}, t]Plus[{{a, b}, {c, d}, {e, f}}, t]If the operation cannot be performed, a message will be emitted and Threaded will stay unevaluated:
Plus[{{a, b, c}, {d, e, f}}, t]Default threading behavior of a listable function f with arrays a and b corresponds to Threaded[b,1]:
SetAttributes[f, Listable]a = Array[x, {2, 2, 2}];
b = Array[y, {2, 2}];Thread the first level of b at the first level of a:
f[a, b] === f[a, Threaded[b, 1]]By default, Threaded[b] threads b at the lowest possible level that does not change the depth of a:
f[a, Threaded[b]] === f[a, Threaded[b, Depth[a] - Depth[b] + 1]]These two threading behaviors are different:
f[a, Threaded[b]] === f[a, Threaded[b, 1]]An array threaded at the lowest level is duplicated as a whole to create a sufficiently deep array for an operation:
mat = (| | | |
| -- | -- | -- |
| 1. | 2. | 3. |
| 4. | 5. | 6. |
| 7. | 8. | 9. |);
arr = Array[Subscript[a, ##]&, {3, 3, 3}];
arr * Threaded[mat]When it is threaded at a higher level, individual entries are duplicated to fill out the array:
arr * Threaded[mat, 1]Threaded[b] is equivalent to Threaded[b,-1-1]:
randomDims = RandomInteger[{2, 4}, RandomInteger[3]];
a = Array[x, Join[randomDims, {3, 2}]];
b = Array[y, {3, 2}];
a + Threaded[b] === a + Threaded[b, -1 -> -1]This can also be expressed as Threaded[b,1-ArrayDepth[b]]:
a + Threaded[b] === a + Threaded[b, 1 -> -ArrayDepth[b]]For a listable function f, an array a and a vector v, the use of Threaded can be reproduced with Inner:
SetAttributes[f, Listable]a = Array[x, {2, 2, 2, 2}];v = {y, z};f[a, Threaded[v]] === Inner[f, a, v, List]A transposition is needed for nondefault threading level:
f[a, Threaded[v, 1]] === Transpose[Inner[f, a, v, List, 1], {2, 3, 4, 1}]f[a, Threaded[v, 2]] === Transpose[Inner[f, a, v, List, 2], {1, 3, 4, 2}]f[a, Threaded[v, 3]] === Transpose[Inner[f, a, v, List, 3], {1, 2, 4, 3}]Compare threading the first level of b at the first level of a, using both Threaded and an explicit Table:
SetAttributes[f, Listable];
a = Array[x, {3, 4, 2, 5, 6}];
b = Array[y, {2, 5}];f[a, Threaded[b, 3]] === Table[f[a[[i, j, k]], b[[k]]], {i, 3}, {j, 4}, {k, 2}]Threading at nondefault levels can be also achieved by using two transpositions:
SetAttributes[f, Listable];
a = Array[x, {3, 4, 2, 5, 6}];
b = Array[y, {2, 5}];This permutation moves levels 3 and 4 of a to levels 1 and 2, leaving level 5 unchanged:
perm = {3, 4, 1, 2, 5};f[a, Threaded[b, 3]] === Transpose[f[Transpose[a, perm], b], InversePermutation[perm]]QuantityArray[mags,units] would correspond to Quantity[mags,Threaded[units]] if Quantity had the Listable attribute:
mags = RandomInteger[10, {3, 4, 2, 2}];
units = {{"Meters", "Seconds"}, {"Kilograms", "Farads"}};SetAttributes[quantity, Listable];
quantity[mags, Threaded[units]] /. quantity -> Quantity//MatrixForm% == QuantityArray[mags, units]See Also
Related Guides
History
Text
Wolfram Research (2022), Threaded, Wolfram Language function, https://reference.wolfram.com/language/ref/Threaded.html.
CMS
Wolfram Language. 2022. "Threaded." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Threaded.html.
APA
Wolfram Language. (2022). Threaded. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Threaded.html
BibTeX
@misc{reference.wolfram_2026_threaded, author="Wolfram Research", title="{Threaded}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/Threaded.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_threaded, organization={Wolfram Research}, title={Threaded}, year={2022}, url={https://reference.wolfram.com/language/ref/Threaded.html}, note=[Accessed: 13-June-2026]}