Want to learn machine learning? Use my machine learning flashcards.

# Apply Operations To Elements

## Preliminaries

```
# Load library
import numpy as np
```

## Create Matrix

```
# Create matrix
matrix = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
```

## Create Vectorized Function

```
# Create a function that adds 100 to something
add_100 = lambda i: i + 100
# Create a vectorized function
vectorized_add_100 = np.vectorize(add_100)
```

## Apply Function To Elements

```
# Apply function to all elements in matrix
vectorized_add_100(matrix)
```

```
array([[101, 102, 103],
[104, 105, 106],
[107, 108, 109]])
```

#### Find an error or bug?

Everything on this site is available on GitHub. Head to and submit a suggested change. You can also message me directly on Twitter.