__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 fromiter(x)
) asx[0]
,x[1]
, …,x[N-1]
. This can also be implemented directly by defining__iter__
. Therefore, for a one-dimensional arrayx
, iteration should produce a sequence of zero-dimensional arraysx[0]
,x[1]
, …,x[N-1]
, whereN
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.