__getitem__¶
- array.__getitem__(key: int | slice | ellipsis | None | Tuple[int | slice | ellipsis | array | None, ...] | array, /) array¶
- Returns - self[key].- Parameters:
- self (array) – array instance. 
- key (Union[int, slice, ellipsis, None, Tuple[Union[int, slice, ellipsis, array, 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.
 - Notes - See Indexing for details on supported indexing semantics. 
- 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- Nis 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.
 - Changed in version 2024.12: Clarified that iteration is defined for one-dimensional arrays.