0

In a Google colab notebook by the Tensorflow team, there was a python line like this:

plt.imshow(discriminator_y(sample_zebra)[0, ..., -1], cmap='RdBu_r')

This is the reference notebook and the entire content of the code cell containing that syntax is

plt.figure(figsize=(8, 8))

plt.subplot(121)
plt.title('Is a real zebra?')
plt.imshow(discriminator_y(sample_zebra)[0, ..., -1], cmap='RdBu_r')

plt.subplot(122)
plt.title('Is a real horse?')
plt.imshow(discriminator_x(sample_horse)[0, ..., -1], cmap='RdBu_r')

plt.show()

What does this syntax with [0, ... , -1] mean?

Aryan Sethi
  • 188
  • 1
  • 8
  • 1
    Literally, it means calling the object's `__getitem__` method with the argument `(0, ..., -1)`, which is a tuple. The `...` is an ellipsis literal. However, I suspect that doesn't really tell you what you want to know. – kaya3 Dec 21 '20 at 15:51
  • 1
    https://stackoverflow.com/questions/772124/what-does-the-ellipsis-object-do – sunnytown Dec 21 '20 at 15:53
  • 1
    I know it's difficult to search for "..." on Google, but you can also search for the python Ellipsis, which is primarily useful for slicing multi-dimensional arrays. – Nick2253 Dec 21 '20 at 15:53

0 Answers0