__getitem__

array.__getitem__(key: int | slice | ellipsis | None | Tuple[int | slice | ellipsis | None, ...] | array, /) array

Returns self[key].

See Indexing for details on supported indexing semantics.

Parameters:
  • self (array) – array instance.

  • key (Union[int, slice, ellipsis, None, Tuple[Union[int, slice, ellipsis, None], ...], array]) – index key.

Returns:
  • out (array) – an array containing the accessed value(s). The returned array must have the same data type as self.

  • .. note:: – When __getitem__ is defined on an object, Python will automatically define iteration (i.e., the behavior from iter(x)) as x[0], x[1], …, x[N-1]. This can also be implemented directly by defining __iter__. Therefore, for a one-dimensional array x, iteration should produce a sequence of zero-dimensional arrays x[0], x[1], …, x[N-1], where N is the number of elements in the array. Iteration behavior for arrays having zero dimensions or more than one dimension is unspecified and thus implementation-defined.