numpy.ndarray.__class_getitem__#

方法

ndarray.__class_getitem__($cls, item, /)#

ndarray[shape, dtype]

Return a parametrized wrapper around the ndarray type.

在 1.22 版新加入.

回傳值:
aliastypes.GenericAlias

A parametrized ndarray type.

也參考

PEP 585

Type hinting generics in standard collections.

numpy.typing.NDArray

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

範例

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