Skip to content

Instantly share code, notes, and snippets.

@yubessy
Last active May 14, 2019 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yubessy/e22186b6669ad14736ec to your computer and use it in GitHub Desktop.
Save yubessy/e22186b6669ad14736ec to your computer and use it in GitHub Desktop.
Python3の...(Ellipsisオブジェクト)について ref: https://qiita.com/yubessy/items/cc1ca4dbc3161f84285e
>>> b = numpy.array([[[1, 2],
... [3, 4]],
... [[5, 6],
... [7, 8]]]) # 2x2x2の多次元配列
>>> b[..., 0] # 第1, 2次元は任意、第3次元のインデックスは0 ---(1)
array([[1, 3],
[5, 7]])
>>> b[:, :, 0] # (1)と同義
array([[1, 3],
[5, 7]])
>>> b[:, 0] # 第1次元は任意、第2次元のインデックスは0、第3次元のインデックスは任意 ---(2)
array([[1, 2],
[5, 6]])
>>> b[:, 0, :] # (2)と同義
array([[1, 2],
[5, 6]])
>>> str(Ellipsis)
'Ellipsis'
>>> str(pass)
File "<stdin>", line 1
str(pass)
^
SyntaxError: invalid syntax
>>> a[0, :]
array([1, 2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment