W3cubDocs

/NumPy 2.4

numpy.ndarray.__class_getitem__

method

ndarray.__class_getitem__($cls, item, /)

ndarray[shape, dtype]

Return a parametrized wrapper around the ndarray type.

New in version 1.22.

Returns:
aliastypes.GenericAlias

A parametrized ndarray type.

See also

PEP 585

Type hinting generics in standard collections.

numpy.typing.NDArray

An ndarray alias generic w.r.t. its dtype.type.

Examples

>>> import numpy as np
>>> np.ndarray[tuple[int], np.dtype[np.uint8]]
numpy.ndarray[tuple[int], numpy.dtype[numpy.uint8]]

© 2005–2024 NumPy Developers
Licensed under the 3-clause BSD License.
https://numpy.org/doc/2.4/reference/generated/numpy.ndarray.__class_getitem__.html