There is a numpy.typing module with an NDArray generic type.


From the Numpy 2.3 docs:
numpy.typing.NDArray = numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]]

A np.ndarray[tuple[Any, ...], np.dtype[ScalarT]] type alias generic w.r.t. its dtype.type.

Can be used during runtime for typing arrays with a given dtype and unspecified shape.

Examples:

>>> import numpy as np
>>> import numpy.typing as npt

>>> print(npt.NDArray)
numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]]

>>> print(npt.NDArray[np.float64])
numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.float64]]

>>> NDArrayInt = npt.NDArray[np.int_]
>>> a: NDArrayInt = np.arange(10)

>>> def func(a: npt.ArrayLike) -> npt.NDArray[Any]:
...     return np.array(a)

As of 2025-07-17, support for shapes is still a work in progress per numpy/numpy#16544.

Answer from Jasha on Stack Overflow
🌐
NumPy
numpy.org › devdocs › reference › typing.html
Typing (numpy.typing) — NumPy v2.6.dev0 Manual
If you really intended to do the above, then you can either use a # type: ignore comment: >>> np.array(x**2 for x in range(10)) # type: ignore
Top answer
1 of 7
124

There is a numpy.typing module with an NDArray generic type.


From the Numpy 2.3 docs:
numpy.typing.NDArray = numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]]

A np.ndarray[tuple[Any, ...], np.dtype[ScalarT]] type alias generic w.r.t. its dtype.type.

Can be used during runtime for typing arrays with a given dtype and unspecified shape.

Examples:

>>> import numpy as np
>>> import numpy.typing as npt

>>> print(npt.NDArray)
numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]]

>>> print(npt.NDArray[np.float64])
numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.float64]]

>>> NDArrayInt = npt.NDArray[np.int_]
>>> a: NDArrayInt = np.arange(10)

>>> def func(a: npt.ArrayLike) -> npt.NDArray[Any]:
...     return np.array(a)

As of 2025-07-17, support for shapes is still a work in progress per numpy/numpy#16544.

2 of 7
75

Update

Check recent numpy versions for a new typing module

https://numpy.org/doc/stable/reference/typing.html#module-numpy.typing

dated answer

It looks like typing module was developed at:

https://github.com/python/typing

The main numpy repository is at

https://github.com/numpy/numpy

Python bugs and commits can be tracked at

http://bugs.python.org/

The usual way of adding a feature is to fork the main repository, develop the feature till it is bomb proof, and then submit a pull request. Obviously at various points in the process you want feedback from other developers. If you can't do the development yourself, then you have to convince someone else that it is a worthwhile project.

cython has a form of annotations, which it uses to generate efficient C code.


You referenced the array-like paragraph in numpy documentation. Note its typing information:

A simple way to find out if the object can be converted to a numpy array using array() is simply to try it interactively and see if it works! (The Python Way).

In other words the numpy developers refuse to be pinned down. They don't, or can't, describe in words what kinds of objects can or cannot be converted to np.ndarray.

In [586]: np.array({'test':1})   # a dictionary
Out[586]: array({'test': 1}, dtype=object)

In [587]: np.array(['one','two'])  # a list
Out[587]: 
array(['one', 'two'], 
      dtype='<U3')

In [589]: np.array({'one','two'})  # a set
Out[589]: array({'one', 'two'}, dtype=object)

For your own functions, an annotation like

def foo(x: np.ndarray) -> np.ndarray:

works. Of course if your function ends up calling some numpy function that passes its argument through asanyarray (as many do), such an annotation would be incomplete, since your input could be a list, or np.matrix, etc.


When evaluating this question and answer, pay attention to the date. 484 was a relatively new PEP back then, and code to make use of it for standard Python still in development. But it looks like the links provided are still valid.

Discussions

python - How to use numpy in optional typing - Stack Overflow
Lets say I want to make a function which takes a lambda function (Callable) as parameter where the lambda function takes a vector as input (defined as numpy array or numpy matrix) and returns a new vector. How do I declare the type signature for the Callable with numpy types? More on stackoverflow.com
🌐 stackoverflow.com
What the latest and greatest way to type hint numpy arrays?
I am aware of two ways: numpy.ndarray[tuple[int, int], float] means rank 2 matrix of floats. Does not distinguish between a shape of (2, 3) and (7, 5) - just enforces that the shape be length 2. numpy.typing.NDArray[float] must contain floats, shape not specified. I have heard of the ability to do numpy.ndarray[tuple[typing.Literal[4]], float] to say an array of floats of shape (4,), but I have not tried it and have heard that support is lacking. More on reddit.com
🌐 r/learnpython
7
3
December 14, 2025
ENH: numpy.typing for type checking, documentation and Numpy compilers
Proposed new feature or change: Type annotations in code using Numpy (and other Python array libraries) can be used for 3 purposes: Python-Numpy compilers (for example Cython or Pythran) documentat... More on github.com
🌐 github.com
2
May 3, 2024
Numpydantic - array typing and validation for pydantic and beyond
Hello everyone! @stefanv recommended i share this here, hopefully y’all find it interesting! I just released a package numpydantic that provides generic typing for array shape and dtype validation using pydantic (and also generally), post here: Dr. jonny phd: "Here's an ~ official ~ release ... More on discuss.scientific-python.org
🌐 discuss.scientific-python.org
1
2
May 25, 2024
🌐
Jack Atkinson
jackatkinson.net › post › numpy_typing
Typing in numpy - Jack Atkinson's Website
April 27, 2025 - This falls slightly under a more general mantras I have come to adopt of “typing in Python is good, but you can’t treat it the same as statically typed languages”, and “don’t try to be overly-specific as this will cause tears”. If a function that returns an NDArray returns what is realistcally a scalar, it is what numpy calls a 0D array .
🌐
w3resource
w3resource.com › numpy › snippet › exploring-numpy-typing.php
Exploring numpy.typing for Enhanced Type Hints
import numpy as np from numpy.typing import NDArray # Define a function to perform element-wise square def square_elements(arr: NDArray[np.int32]) -> NDArray[np.int32]: return arr ** 2 # Test the function array = np.array([1, 2, 3], dtype=np.int32) squared_array = square_elements(array) print("Original array:", array) print("Squared array:", squared_array) ... Both the input and output of the function are strictly typed, ensuring consistency. ... 1. Performance: Type hints do not affect runtime performance. They are ignored by the Python interpreter. 2. Backward Compatibility: The numpy.typing module is available from NumPy 1.21.0.
🌐
NumPy
numpy.org › doc › 2.3 › reference › typing.html
Typing (numpy.typing) — NumPy v2.3 Manual
The dtype of numpy.recarray, and the Creating record arrays functions in general, can be specified in one of two ways: Directly via the dtype argument. With up to five helper arguments that operate via numpy.rec.format_parser: formats, names, titles, aligned and byteorder.
🌐
Medium
medium.com › @goldengrisha › using-numpy-typing-for-type-safe-list-handling-in-python-35f8c99c76ac
Using numpy.typing for Type-Safe List Handling in Python | by Gregory Kovalchuk | Medium
February 19, 2025 - By using numpy.typing, we can write safer, more readable code while leveraging the power of static type checking tools like MyPy. Whether you want strict type enforcement with NDArray or flexibility with ArrayLike, these type hints help make your NumPy-based functions more robust.
🌐
PyPI
pypi.org › project › nptyping
nptyping · PyPI
>>> from nptyping import RecArray >>> arr = np.array([("Peter", 34)], dtype=[("name", "U10"), ("age", "i4")]) >>> rec_arr = arr.view(np.recarray) >>> isinstance(rec_arr, RecArray[Any, Structure["name: Str, age: Int"]]) True
      » pip install nptyping
    
Published: Feb 20, 2023
Version: 2.5.0
Find elsewhere
🌐
NumPy
numpy.org › doc › stable › reference › typing.html
Typing (numpy.typing) — NumPy v2.5 Manual
If you really intended to do the above, then you can either use a # type: ignore comment: >>> np.array(x**2 for x in range(10)) # type: ignore
🌐
NumPy
numpy.org › doc › stable › reference › typing.html
Typing (numpy.typing) — NumPy v2.4 Manual
The dtype of numpy.recarray, and the Creating record arrays functions in general, can be specified in one of two ways: Directly via the dtype argument. With up to five helper arguments that operate via numpy.rec.format_parser: formats, names, titles, aligned and byteorder.
🌐
Rossbar
rossbar.github.io › numpy › reference › typing.html
Typing (numpy.typing) — NumPy v1.20.dev0 Manual
Roughly speaking, typing.ArrayLike is “objects that can be used as inputs to np.array” and typing.DtypeLike is “objects that can be used as inputs to np.dtype”. NumPy is very flexible. Trying to describe the full range of possibilities statically would result in types that are not very helpful.
🌐
GitHub
github.com › numpy › numpy › issues › 26380
ENH: numpy.typing for type checking, documentation and Numpy compilers · Issue #26380 · numpy/numpy
May 3, 2024 - Proposed new feature or change: Type annotations in code using Numpy (and other Python array libraries) can be used for 3 purposes: Python-Numpy compilers (for example Cython or Pythran) documentation type checking Currently numpy.typing...
Author: numpy
🌐
Medium
medium.com › data-science-collective › do-more-with-numpy-array-type-hints-annotate-validate-shape-dtype-09f81c496746
Do More with NumPy Array Type Hints: Annotate & Validate Shape & Dtype | by Christopher Ariza | Data Science Collective | Medium
May 26, 2025 - Thus, a tuple[int] can specify a 1D array; a tuple[int, int, int] can specify a 3D array; a tuple[int, …], specifying a tuple of zero or more integers, denotes an N-dimensional array. It might be possible in the future to type-check an np.ndarray with specific magnitudes per dimension (using Literal), but this is not yet broadly supported. The NumPy dtype object defines element types and, for some types, other characteristics such as size (for Unicode and string types) or unit (for np.datetime64 types).
🌐
Scientific Python
discuss.scientific-python.org › contributor & development discussion
Numpydantic - array typing and validation for pydantic and beyond - Contributor & Development Discussion - Scientific Python
May 25, 2024 - Hello everyone! @stefanv recommended i share this here, hopefully y’all find it interesting! I just released a package numpydantic that provides generic typing for array shape and dtype validation using pydantic (and also generally), post here: Dr. jonny phd: "Here's an ~ official ~ release announcement for #…" - Neuromatch Social The idea is that we not only want to be able to specify arrays in pydantic, specify shape and dtype constraints for those arrays, but also be able to ...
🌐
Python.org
discuss.python.org › python help
How to type annotate mathematical operations that supports built-in numerics, collections and numpy arrays? - Python Help - Discussions on Python.org
April 2, 2022 - In scientific code that deals with mathematical operations, before type annotations, it is common to assume that any mathematical function could take in a numpy array. To be explicit you just add to your docstring that you can take array_like or ndarray (as is conventional in NumFocus project docs).
🌐
NumPy
numpy.org › doc › 1.20 › reference › typing.html
Typing (numpy.typing) — NumPy v1.20 Manual
January 31, 2021 - If you want to use these types in earlier versions of Python, you should install the typing-extensions package. Large parts of the NumPy API have PEP-484-style type annotations. In addition a number of type aliases are available to users, most prominently the two below: ArrayLike: objects that can be converted to arrays
🌐
GitHub
github.com › agronholm › typeguard › issues › 195
Support for `numpy.typing.NDArray` · Issue #195 · agronholm/typeguard
July 8, 2021 - NumPy has introduced a new typing library: https://numpy.org/devdocs/reference/typing.html. One part of it is that you can mention the dtype of elements in the type: import numpy.typing as npt ... def some_function( a_float_array: npt.ND...
Author: agronholm
🌐
InfoWorld
infoworld.com › home › software development › programming languages › python
NumPy 1.20 introduces type annotations | InfoWorld
February 26, 2021 - There also is a new numpy.typing module containing useful types for end users. Currently available types include ArrayLike, for objects that can be coerced into an array, and DtypeLike, for objects that can be coerced into a dtype.
🌐
W3Schools
w3schools.com › python › numpy › numpy_data_types.asp
NumPy Data Types
The astype() function creates a copy of the array, and allows you to specify the data type as a parameter. The data type can be specified using a string, like 'f' for float, 'i' for integer etc. or you can use the data type directly like float ...