-1
X_train[y_train == y, :, :]
all_obs[train_index, ...]

What do this two lines of code means? what does comma means here? and what does "..." means here?

slhttc
  • 11
  • 4
  • 3
    http://stackoverflow.com/questions/772124/what-does-the-python-ellipsis-object-do . This link partially answers this question. – SivNiz May 08 '16 at 14:23
  • 2
    You've almost certainly encountered the code in the context of NumPy arrays and it would be helpful to put this context in the question. Did you search the documentation or check any other answers on Stack Overflow? There's a lot of information already out there that explains the meaning of the code. – Alex Riley May 08 '16 at 14:35

1 Answers1

0

If you define a class that implements __getitem__ you can examine the details:

class Foo(object):
    def __getitem__(self, *xs, **kws):
        return [xs, kws]

X_train = Foo()
all_obs = Foo()

y_train = 123
y = 123
train_index = 456

print X_train[y_train == y, :, :]
print all_obs[train_index, ...]

Output:

[((True, slice(None, None, None), slice(None, None, None)),), {}]
[((456, Ellipsis),), {}]

Looks like the colon defines an empty slice object, and the ellipsis is discussed in the links provided in comments above (What does the Python Ellipsis object do?).

Community
  • 1
  • 1
FMc
  • 41,963
  • 13
  • 79
  • 132