Learning machine learning? Try my machine learning flashcards or Machine Learning with Python Cookbook.

# Selecting Elements In An Array

## Preliminaries

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

## Create Vector

```
# Create row vector
vector = np.array([1, 2, 3, 4, 5, 6])
```

## Select Element

```
# Select second element
vector[1]
```

```
2
```

## Create Matrix

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

## Select Element

```
# Select second row, second column
matrix[1,1]
```

```
5
```

## Create Tensor

```
# Create matrix
tensor = np.array([
[[[1, 1], [1, 1]], [[2, 2], [2, 2]]],
[[[3, 3], [3, 3]], [[4, 4], [4, 4]]]
])
```

## Select Element

```
# Select second element of each of the three dimensions
tensor[1,1,1]
```

```
array([4, 4])
```

#### 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.