What does t[…, 0] means in numpy/pytorch/tensorflow?

Alvaro Durán Tovar
Deep Learning made easy
1 min readAug 16, 2019

While going through this very interesting video TensorFlow Probability: Learning with confidence I found some expression that I didn’t recognize, t being a tensor:

t[…, 0]

Everything we put into brackets when working with tensors (call it arrays in numpy?) is used for slicing, for selecting different parts of the data.

In this case that syntax means:

  • For the last dimension select only index 0
  • Select everything for the preceding dimensions

Let’s see some examples. First setup the data, for examples lets create an array like if it were an image (3 channels, 4 width, 4 height):

Let’s do some slicing now:

I hope you learned something new today!!

--

--