---
title: "MapThread"
language: "en"
type: "Symbol"
summary: "MapThread[f, {{a1, a2, ...}, {b1, b2, ...}, ...}] gives {f[a1, b1, ...], f[a2, b2, ...], ...}. MapThread[f, {expr1, expr2, ...}, n] applies f to the parts of the expri at level n. MapThread[f] represents an operator form of MapThread that can be applied to an expression."
keywords: 
- multivariate Map
- parallel form of Map
- foreach
- zip
canonical_url: "https://reference.wolfram.com/language/ref/MapThread.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Applying Functions to Lists"
    link: "https://reference.wolfram.com/language/guide/ApplyingFunctionsToLists.en.md"
  - 
    title: "Functional Programming"
    link: "https://reference.wolfram.com/language/guide/FunctionalProgramming.en.md"
  - 
    title: "List Manipulation"
    link: "https://reference.wolfram.com/language/guide/ListManipulation.en.md"
related_functions: 
  - 
    title: "Apply"
    link: "https://reference.wolfram.com/language/ref/Apply.en.md"
  - 
    title: "Map"
    link: "https://reference.wolfram.com/language/ref/Map.en.md"
  - 
    title: "Thread"
    link: "https://reference.wolfram.com/language/ref/Thread.en.md"
  - 
    title: "Threaded"
    link: "https://reference.wolfram.com/language/ref/Threaded.en.md"
  - 
    title: "Inner"
    link: "https://reference.wolfram.com/language/ref/Inner.en.md"
  - 
    title: "Transpose"
    link: "https://reference.wolfram.com/language/ref/Transpose.en.md"
  - 
    title: "Comap"
    link: "https://reference.wolfram.com/language/ref/Comap.en.md"
  - 
    title: "Through"
    link: "https://reference.wolfram.com/language/ref/Through.en.md"
related_tutorials: 
  - 
    title: "Applying Functions to Parts of Expressions"
    link: "https://reference.wolfram.com/language/tutorial/FunctionalOperations.en.md#28027"
---
# MapThread

MapThread[f, {{a1, a2, …}, {b1, b2, …}, …}] gives {f[a1, b1, …], f[a2, b2, …], …}. 

MapThread[f, {expr1, expr2, …}, n] applies f to the parts of the expri at level n.

MapThread[f] represents an operator form of MapThread that can be applied to an expression.

## Details

* ``MapThread`` works on ``Association`` objects.

* ``MapThread[f][expr]`` is equivalent to ``MapThread[f, expr]``.

* ``Parallelize[MapThread[f, {{a1, a2, …}, {b1, b2, …}, …}]]`` computes ``MapThread[f, {{a1, a2, …}, {b1, b2, …}, …}]`` in parallel on all subkernels. »

---

## Examples (17)

### Basic Examples (4)

Apply ``f`` to corresponding pairs of elements:

```wl
In[1]:= MapThread[f, {{a, b, c}, {x, y, z}}]

Out[1]= {f[a, x], f[b, y], f[c, z]}
```

---

Apply ``f`` to elements of a matrix:

```wl
In[1]:= MapThread[f, {{{a, b}, {c, d}}, {{u, v}, {s, t}}}, 2]

Out[1]= {{f[a, u], f[b, v]}, {f[c, s], f[d, t]}}
```

---

Apply ``f`` to corresponding values of associations:

```wl
In[1]:= MapThread[f, {<|a -> 1|>, <|a -> 2|>}]

Out[1]= <|a -> f[1, 2]|>
```

---

Use the operator form of ``MapThread`` :

```wl
In[1]:= MapThread[f][{{a, b, c, d}, {1, 2, 3, 4}}]

Out[1]= {f[a, 1], f[b, 2], f[c, 3], f[d, 4]}
```

### Scope (2)

By default, ``MapThread`` threads over level 1 of the arguments:

```wl
In[1]:= MapThread[f, {{{a, b}, {c, d}}, {{u, v}, {w, x}}}]

Out[1]= {f[{a, b}, {u, v}], f[{c, d}, {w, x}]}
```

Thread over level 2:

```wl
In[2]:= MapThread[f, {{{a, b}, {c, d}}, {{u, v}, {w, x}}}, 2]

Out[2]= {{f[a, u], f[b, v]}, {f[c, w], f[d, x]}}
```

---

``MapThread`` works with any number of expressions:

```wl
In[1]:= MapThread[f, {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}}]

Out[1]= {f[1, 4, 7, 10], f[2, 5, 8, 11], f[3, 6, 9, 12]}
```

### Applications (3)

Set up an outer totalistic cellular automaton:

```wl
In[1]:= t = RandomInteger[1, 10]

Out[1]= {0, 0, 0, 0, 0, 0, 1, 0, 0, 0}

In[2]:= MapThread[f, {t, RotateLeft[t] + RotateRight[t]}]

Out[2]= {f[0, 0], f[0, 0], f[0, 0], f[0, 0], f[0, 0], f[0, 1], f[1, 0], f[0, 1], f[0, 0], f[0, 0]}
```

---

Divide eigenvectors by their corresponding eigenvalues:

```wl
In[1]:= Eigensystem[{{1, 3}, {2, 7}}]

Out[1]= {{4 + Sqrt[15], 4 - Sqrt[15]}, {{-(7/2) + (1/2) (4 + Sqrt[15]), 1}, {-(7/2) + (1/2) (4 - Sqrt[15]), 1}}}

In[2]:= MapThread[#2 / #1&, %]//FullSimplify

Out[2]= {{(1/2) (-27 + 7 Sqrt[15]), 4 - Sqrt[15]}, {(1/2) (-27 - 7 Sqrt[15]), 4 + Sqrt[15]}}
```

---

Apply the functions in a list to corresponding arguments:

```wl
In[1]:= MapThread[#1@#2&, {{f, g, h}, {x, y, z}}]

Out[1]= {f[x], g[y], h[z]}
```

### Properties & Relations (6)

Add columns of elements in a matrix:

```wl
In[1]:= MapThread[Plus, {{a, b, c}, {u, v, w}, {x, y, z}}]

Out[1]= {a + u + x, b + v + y, c + w + z}

In[2]:= Total[{{a, b, c}, {u, v, w}, {x, y, z}}]

Out[2]= {a + u + x, b + v + y, c + w + z}
```

---

Get lists of elements in columns of a matrix:

```wl
In[1]:= MapThread[List, {{a, b, c}, {u, v, w}, {x, y, z}}]

Out[1]= {{a, u, x}, {b, v, y}, {c, w, z}}

In[2]:= Transpose[{{a, b, c}, {u, v, w}, {x, y, z}}]

Out[2]= {{a, u, x}, {b, v, y}, {c, w, z}}
```

---

``MapThread`` works like ``Thread``, but takes the function and arguments separately:

```wl
In[1]:= MapThread[f, {{a, b, c}, {x, y, z}}]

Out[1]= {f[a, x], f[b, y], f[c, z]}

In[2]:= Thread[f[{a, b, c}, {x, y, z}]]

Out[2]= {f[a, x], f[b, y], f[c, z]}
```

---

``Thread`` evaluates the whole expression before threading:

```wl
In[1]:= Thread[D[{x, x y, x z}, {x, y, z}]]
```

D::dvar: Multiple derivative specifier {x,y,z} does not have the form {variable, n}, where n is a non-negative machine integer.

```wl
Out[1]= {1, x, x}
```

``MapThread`` takes the function and its arguments separately:

```wl
In[2]:= MapThread[D, {{x, x y, x z}, {x, y, z}}]

Out[2]= {1, x, x}
```

---

``MapThread`` is a generalization of ``Map`` to functions of several variables:

```wl
In[1]:= Map[f, {a, b, c}]

Out[1]= {f[a], f[b], f[c]}

In[2]:= MapThread[f, {{a, b, c}}]

Out[2]= {f[a], f[b], f[c]}

In[3]:= MapThread[f, {{a, b, c}, {x, y, z}}]

Out[3]= {f[a, x], f[b, y], f[c, z]}
```

---

Compute ``MapThread`` in parallel:

```wl
In[1]:= Parallelize[MapThread[f, {{a, b, c}, {u, v, w}}]]

Out[1]= {f[a, u], f[b, v], f[c, w]}
```

### Possible Issues (2)

All arguments must be lists of the same length:

```wl
In[1]:= MapThread[f, {{a, b, c}, t, {u, v, w}}]
```

MapThread::mptd: Object t at position {2, 2} in MapThread[f,{{a,b,c},t,{u,v,w}}] has only 0 of required 1 dimensions.

```wl
Out[1]= MapThread[f, {{a, b, c}, t, {u, v, w}}]
```

``Thread`` repeats nonlist arguments as needed:

```wl
In[2]:= Thread[f[{a, b, c}, t, {u, v, w}]]

Out[2]= {f[a, t, u], f[b, t, v], f[c, t, w]}
```

---

``MapThread`` combines associations in a list:

```wl
In[1]:= MapThread[f, {<|a -> 1|>, <|a -> 2|>}]

Out[1]= <|a -> f[1, 2]|>
```

Use ``Apply`` to combine values of an association:

```wl
In[2]:= Apply[f, <|a -> {1, 2}, b -> {3, 4}|>, {1}]

Out[2]= <|a -> f[1, 2], b -> f[3, 4]|>
```

## See Also

* [`Apply`](https://reference.wolfram.com/language/ref/Apply.en.md)
* [`Map`](https://reference.wolfram.com/language/ref/Map.en.md)
* [`Thread`](https://reference.wolfram.com/language/ref/Thread.en.md)
* [`Threaded`](https://reference.wolfram.com/language/ref/Threaded.en.md)
* [`Inner`](https://reference.wolfram.com/language/ref/Inner.en.md)
* [`Transpose`](https://reference.wolfram.com/language/ref/Transpose.en.md)
* [`Comap`](https://reference.wolfram.com/language/ref/Comap.en.md)
* [`Through`](https://reference.wolfram.com/language/ref/Through.en.md)

## Tech Notes

* [Applying Functions to Parts of Expressions](https://reference.wolfram.com/language/tutorial/FunctionalOperations.en.md#28027)

## Related Guides

* [Applying Functions to Lists](https://reference.wolfram.com/language/guide/ApplyingFunctionsToLists.en.md)
* [Functional Programming](https://reference.wolfram.com/language/guide/FunctionalProgramming.en.md)
* [List Manipulation](https://reference.wolfram.com/language/guide/ListManipulation.en.md)

## History

* Introduced in 1991 (2.0) \| [Updated in 2014 (10.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn100.en.md) ▪ [2016 (11.0)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn110.en.md) ▪ [2017 (11.1)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn111.en.md)