summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2020-09-16 15:03:45 -0600
committerGitHub <noreply@github.com>2020-09-16 15:03:45 -0600
commitf1f1436b853f3855d75667ab4055cce06960fda9 (patch)
tree6cf1d2de8007a404e0ed42aec27109b59e03eccd
parente731e8676118c48770368eb470fed2d77fe82847 (diff)
parentf64d9afed7fb473914dbe88037c665c501e4bf68 (diff)
downloadnumpy-f1f1436b853f3855d75667ab4055cce06960fda9.tar.gz
Merge pull request #17309 from BvB93/numeric-move
MAINT: Move the `fromnumeric` annotations to their own stub file
-rw-r--r--numpy/__init__.pyi560
-rw-r--r--numpy/core/fromnumeric.pyi492
2 files changed, 576 insertions, 476 deletions
diff --git a/numpy/__init__.pyi b/numpy/__init__.pyi
index bf54207a4..d4eda6b31 100644
--- a/numpy/__init__.pyi
+++ b/numpy/__init__.pyi
@@ -66,10 +66,93 @@ from numpy.core.function_base import (
geomspace,
)
+from numpy.core.fromnumeric import (
+ take,
+ reshape,
+ choose,
+ repeat,
+ put,
+ swapaxes,
+ transpose,
+ partition,
+ argpartition,
+ sort,
+ argsort,
+ argmax,
+ argmin,
+ searchsorted,
+ resize,
+ squeeze,
+ diagonal,
+ trace,
+ ravel,
+ nonzero,
+ shape,
+ compress,
+ clip,
+ sum,
+ all,
+ any,
+ cumsum,
+ ptp,
+ amax,
+ amin,
+ prod,
+ cumprod,
+ ndim,
+ size,
+ around,
+ mean,
+ std,
+ var,
+)
+
# Add an object to `__all__` if their stubs are defined in an external file;
# their stubs will not be recognized otherwise.
# NOTE: This is redundant for objects defined within this file.
-__all__ = ["linspace", "logspace", "geomspace"]
+__all__ = [
+ "linspace",
+ "logspace",
+ "geomspace",
+ "take",
+ "reshape",
+ "choose",
+ "repeat",
+ "put",
+ "swapaxes",
+ "transpose",
+ "partition",
+ "argpartition",
+ "sort",
+ "argsort",
+ "argmax",
+ "argmin",
+ "searchsorted",
+ "resize",
+ "squeeze",
+ "diagonal",
+ "trace",
+ "ravel",
+ "nonzero",
+ "shape",
+ "compress",
+ "clip",
+ "sum",
+ "all",
+ "any",
+ "cumsum",
+ "ptp",
+ "amax",
+ "amin",
+ "prod",
+ "cumprod",
+ "ndim",
+ "size",
+ "around",
+ "mean",
+ "std",
+ "var",
+]
# TODO: remove when the full numpy namespace is defined
def __getattr__(name: str) -> Any: ...
@@ -998,481 +1081,6 @@ def find_common_type(
array_types: Sequence[DtypeLike], scalar_types: Sequence[DtypeLike]
) -> dtype: ...
-# Functions from np.core.fromnumeric
-_Mode = Literal["raise", "wrap", "clip"]
-_PartitionKind = Literal["introselect"]
-_SortKind = Literal["quicksort", "mergesort", "heapsort", "stable"]
-_Side = Literal["left", "right"]
-
-# Various annotations for scalars
-
-# While dt.datetime and dt.timedelta are not technically part of NumPy,
-# they are one of the rare few builtin scalars which serve as valid return types.
-# See https://github.com/numpy/numpy-stubs/pull/67#discussion_r412604113.
-_ScalarNumpy = Union[generic, dt.datetime, dt.timedelta]
-_ScalarBuiltin = Union[str, bytes, dt.date, dt.timedelta, bool, int, float, complex]
-_Scalar = Union[_ScalarBuiltin, _ScalarNumpy]
-
-# Integers and booleans can generally be used interchangeably
-_ScalarIntOrBool = TypeVar("_ScalarIntOrBool", bound=Union[integer, bool_])
-_ScalarGeneric = TypeVar("_ScalarGeneric", bound=generic)
-_ScalarGenericDT = TypeVar(
- "_ScalarGenericDT", bound=Union[dt.datetime, dt.timedelta, generic]
-)
-
-_Number = TypeVar('_Number', bound=number)
_NumberLike = Union[int, float, complex, number, bool_]
-
-# An array-like object consisting of integers
_IntLike = Union[int, integer]
_BoolLike = Union[bool, bool_]
-_IntOrBool = Union[_IntLike, _BoolLike]
-_ArrayLikeIntNested = ArrayLike # TODO: wait for support for recursive types
-_ArrayLikeBoolNested = ArrayLike # TODO: wait for support for recursive types
-
-# Integers and booleans can generally be used interchangeably
-_ArrayLikeIntOrBool = Union[
- _IntOrBool,
- ndarray,
- Sequence[_IntOrBool],
- Sequence[_ArrayLikeIntNested],
- Sequence[_ArrayLikeBoolNested],
-]
-_ArrayLikeBool = Union[
- _BoolLike,
- Sequence[_BoolLike],
- ndarray
-]
-
-# The signature of take() follows a common theme with its overloads:
-# 1. A generic comes in; the same generic comes out
-# 2. A scalar comes in; a generic comes out
-# 3. An array-like object comes in; some keyword ensures that a generic comes out
-# 4. An array-like object comes in; an ndarray or generic comes out
-@overload
-def take(
- a: _ScalarGenericDT,
- indices: int,
- axis: Optional[int] = ...,
- out: Optional[ndarray] = ...,
- mode: _Mode = ...,
-) -> _ScalarGenericDT: ...
-@overload
-def take(
- a: _Scalar,
- indices: int,
- axis: Optional[int] = ...,
- out: Optional[ndarray] = ...,
- mode: _Mode = ...,
-) -> _ScalarNumpy: ...
-@overload
-def take(
- a: ArrayLike,
- indices: int,
- axis: Optional[int] = ...,
- out: Optional[ndarray] = ...,
- mode: _Mode = ...,
-) -> _ScalarNumpy: ...
-@overload
-def take(
- a: ArrayLike,
- indices: _ArrayLikeIntOrBool,
- axis: Optional[int] = ...,
- out: Optional[ndarray] = ...,
- mode: _Mode = ...,
-) -> Union[_ScalarNumpy, ndarray]: ...
-def reshape(a: ArrayLike, newshape: _ShapeLike, order: _OrderACF = ...) -> ndarray: ...
-@overload
-def choose(
- a: _ScalarIntOrBool,
- choices: ArrayLike,
- out: Optional[ndarray] = ...,
- mode: _Mode = ...,
-) -> _ScalarIntOrBool: ...
-@overload
-def choose(
- a: _IntOrBool, choices: ArrayLike, out: Optional[ndarray] = ..., mode: _Mode = ...
-) -> Union[integer, bool_]: ...
-@overload
-def choose(
- a: _ArrayLikeIntOrBool,
- choices: ArrayLike,
- out: Optional[ndarray] = ...,
- mode: _Mode = ...,
-) -> ndarray: ...
-def repeat(
- a: ArrayLike, repeats: _ArrayLikeIntOrBool, axis: Optional[int] = ...
-) -> ndarray: ...
-def put(
- a: ndarray, ind: _ArrayLikeIntOrBool, v: ArrayLike, mode: _Mode = ...
-) -> None: ...
-def swapaxes(a: ArrayLike, axis1: int, axis2: int) -> ndarray: ...
-def transpose(
- a: ArrayLike, axes: Union[None, Sequence[int], ndarray] = ...
-) -> ndarray: ...
-def partition(
- a: ArrayLike,
- kth: _ArrayLikeIntOrBool,
- axis: Optional[int] = ...,
- kind: _PartitionKind = ...,
- order: Union[None, str, Sequence[str]] = ...,
-) -> ndarray: ...
-@overload
-def argpartition(
- a: generic,
- kth: _ArrayLikeIntOrBool,
- axis: Optional[int] = ...,
- kind: _PartitionKind = ...,
- order: Union[None, str, Sequence[str]] = ...,
-) -> integer: ...
-@overload
-def argpartition(
- a: _ScalarBuiltin,
- kth: _ArrayLikeIntOrBool,
- axis: Optional[int] = ...,
- kind: _PartitionKind = ...,
- order: Union[None, str, Sequence[str]] = ...,
-) -> ndarray: ...
-@overload
-def argpartition(
- a: ArrayLike,
- kth: _ArrayLikeIntOrBool,
- axis: Optional[int] = ...,
- kind: _PartitionKind = ...,
- order: Union[None, str, Sequence[str]] = ...,
-) -> ndarray: ...
-def sort(
- a: ArrayLike,
- axis: Optional[int] = ...,
- kind: Optional[_SortKind] = ...,
- order: Union[None, str, Sequence[str]] = ...,
-) -> ndarray: ...
-def argsort(
- a: ArrayLike,
- axis: Optional[int] = ...,
- kind: Optional[_SortKind] = ...,
- order: Union[None, str, Sequence[str]] = ...,
-) -> ndarray: ...
-@overload
-def argmax(a: ArrayLike, axis: None = ..., out: Optional[ndarray] = ...) -> integer: ...
-@overload
-def argmax(
- a: ArrayLike, axis: int = ..., out: Optional[ndarray] = ...
-) -> Union[integer, ndarray]: ...
-@overload
-def argmin(a: ArrayLike, axis: None = ..., out: Optional[ndarray] = ...) -> integer: ...
-@overload
-def argmin(
- a: ArrayLike, axis: int = ..., out: Optional[ndarray] = ...
-) -> Union[integer, ndarray]: ...
-@overload
-def searchsorted(
- a: ArrayLike,
- v: _Scalar,
- side: _Side = ...,
- sorter: Optional[_ArrayLikeIntOrBool] = ..., # 1D int array
-) -> integer: ...
-@overload
-def searchsorted(
- a: ArrayLike,
- v: ArrayLike,
- side: _Side = ...,
- sorter: Optional[_ArrayLikeIntOrBool] = ..., # 1D int array
-) -> ndarray: ...
-def resize(a: ArrayLike, new_shape: _ShapeLike) -> ndarray: ...
-@overload
-def squeeze(a: _ScalarGeneric, axis: Optional[_ShapeLike] = ...) -> _ScalarGeneric: ...
-@overload
-def squeeze(a: ArrayLike, axis: Optional[_ShapeLike] = ...) -> ndarray: ...
-def diagonal(
- a: ArrayLike, offset: int = ..., axis1: int = ..., axis2: int = ... # >= 2D array
-) -> ndarray: ...
-def trace(
- a: ArrayLike, # >= 2D array
- offset: int = ...,
- axis1: int = ...,
- axis2: int = ...,
- dtype: DtypeLike = ...,
- out: Optional[ndarray] = ...,
-) -> Union[number, ndarray]: ...
-def ravel(a: ArrayLike, order: _OrderKACF = ...) -> ndarray: ...
-def nonzero(a: ArrayLike) -> Tuple[ndarray, ...]: ...
-def shape(a: ArrayLike) -> _Shape: ...
-def compress(
- condition: ArrayLike, # 1D bool array
- a: ArrayLike,
- axis: Optional[int] = ...,
- out: Optional[ndarray] = ...,
-) -> ndarray: ...
-@overload
-def clip(
- a: _Number,
- a_min: ArrayLike,
- a_max: Optional[ArrayLike],
- out: Optional[ndarray] = ...,
- **kwargs: Any,
-) -> _Number: ...
-@overload
-def clip(
- a: _Number,
- a_min: None,
- a_max: ArrayLike,
- out: Optional[ndarray] = ...,
- **kwargs: Any,
-) -> _Number: ...
-@overload
-def clip(
- a: ArrayLike,
- a_min: ArrayLike,
- a_max: Optional[ArrayLike],
- out: Optional[ndarray] = ...,
- **kwargs: Any,
-) -> Union[number, ndarray]: ...
-@overload
-def clip(
- a: ArrayLike,
- a_min: None,
- a_max: ArrayLike,
- out: Optional[ndarray] = ...,
- **kwargs: Any,
-) -> Union[number, ndarray]: ...
-@overload
-def sum(
- a: _Number,
- axis: Optional[_ShapeLike] = ...,
- dtype: DtypeLike = ...,
- out: Optional[ndarray] = ...,
- keepdims: bool = ...,
- initial: _NumberLike = ...,
- where: _ArrayLikeBool = ...,
-) -> _Number: ...
-@overload
-def sum(
- a: ArrayLike,
- axis: _ShapeLike = ...,
- dtype: DtypeLike = ...,
- out: Optional[ndarray] = ...,
- keepdims: bool = ...,
- initial: _NumberLike = ...,
- where: _ArrayLikeBool = ...,
-) -> Union[number, ndarray]: ...
-@overload
-def all(
- a: ArrayLike,
- axis: None = ...,
- out: Optional[ndarray] = ...,
- keepdims: Literal[False] = ...,
-) -> bool_: ...
-@overload
-def all(
- a: ArrayLike,
- axis: Optional[_ShapeLike] = ...,
- out: Optional[ndarray] = ...,
- keepdims: bool = ...,
-) -> Union[bool_, ndarray]: ...
-@overload
-def any(
- a: ArrayLike,
- axis: None = ...,
- out: Optional[ndarray] = ...,
- keepdims: Literal[False] = ...,
-) -> bool_: ...
-@overload
-def any(
- a: ArrayLike,
- axis: Optional[_ShapeLike] = ...,
- out: Optional[ndarray] = ...,
- keepdims: bool = ...,
-) -> Union[bool_, ndarray]: ...
-def cumsum(
- a: ArrayLike,
- axis: Optional[int] = ...,
- dtype: DtypeLike = ...,
- out: Optional[ndarray] = ...,
-) -> ndarray: ...
-@overload
-def ptp(
- a: _Number,
- axis: Optional[_ShapeLike] = ...,
- out: Optional[ndarray] = ...,
- keepdims: bool = ...,
-) -> _Number: ...
-@overload
-def ptp(
- a: ArrayLike,
- axis: None = ...,
- out: Optional[ndarray] = ...,
- keepdims: Literal[False] = ...,
-) -> number: ...
-@overload
-def ptp(
- a: ArrayLike,
- axis: Optional[_ShapeLike] = ...,
- out: Optional[ndarray] = ...,
- keepdims: bool = ...,
-) -> Union[number, ndarray]: ...
-@overload
-def amax(
- a: _Number,
- axis: Optional[_ShapeLike] = ...,
- out: Optional[ndarray] = ...,
- keepdims: bool = ...,
- initial: _NumberLike = ...,
- where: _ArrayLikeBool = ...,
-) -> _Number: ...
-@overload
-def amax(
- a: ArrayLike,
- axis: None = ...,
- out: Optional[ndarray] = ...,
- keepdims: Literal[False] = ...,
- initial: _NumberLike = ...,
- where: _ArrayLikeBool = ...,
-) -> number: ...
-@overload
-def amax(
- a: ArrayLike,
- axis: Optional[_ShapeLike] = ...,
- out: Optional[ndarray] = ...,
- keepdims: bool = ...,
- initial: _NumberLike = ...,
- where: _ArrayLikeBool = ...,
-) -> Union[number, ndarray]: ...
-@overload
-def amin(
- a: _Number,
- axis: Optional[_ShapeLike] = ...,
- out: Optional[ndarray] = ...,
- keepdims: bool = ...,
- initial: _NumberLike = ...,
- where: _ArrayLikeBool = ...,
-) -> _Number: ...
-@overload
-def amin(
- a: ArrayLike,
- axis: None = ...,
- out: Optional[ndarray] = ...,
- keepdims: Literal[False] = ...,
- initial: _NumberLike = ...,
- where: _ArrayLikeBool = ...,
-) -> number: ...
-@overload
-def amin(
- a: ArrayLike,
- axis: Optional[_ShapeLike] = ...,
- out: Optional[ndarray] = ...,
- keepdims: bool = ...,
- initial: _NumberLike = ...,
- where: _ArrayLikeBool = ...,
-) -> Union[number, ndarray]: ...
-
-# TODO: `np.prod()``: For object arrays `initial` does not necessarily
-# have to be a numerical scalar.
-# The only requirement is that it is compatible
-# with the `.__mul__()` method(s) of the passed array's elements.
-
-# Note that the same situation holds for all wrappers around
-# `np.ufunc.reduce`, e.g. `np.sum()` (`.__add__()`).
-
-@overload
-def prod(
- a: _Number,
- axis: Optional[_ShapeLike] = ...,
- dtype: DtypeLike = ...,
- out: None = ...,
- keepdims: bool = ...,
- initial: _NumberLike = ...,
- where: _ArrayLikeBool = ...,
-) -> _Number: ...
-@overload
-def prod(
- a: ArrayLike,
- axis: None = ...,
- dtype: DtypeLike = ...,
- out: None = ...,
- keepdims: Literal[False] = ...,
- initial: _NumberLike = ...,
- where: _ArrayLikeBool = ...,
-) -> number: ...
-@overload
-def prod(
- a: ArrayLike,
- axis: Optional[_ShapeLike] = ...,
- dtype: DtypeLike = ...,
- out: Optional[ndarray] = ...,
- keepdims: bool = ...,
- initial: _NumberLike = ...,
- where: _ArrayLikeBool = ...,
-) -> Union[number, ndarray]: ...
-def cumprod(
- a: ArrayLike,
- axis: Optional[int] = ...,
- dtype: DtypeLike = ...,
- out: Optional[ndarray] = ...,
-) -> ndarray: ...
-def ndim(a: ArrayLike) -> int: ...
-def size(a: ArrayLike, axis: Optional[int] = ...) -> int: ...
-@overload
-def around(
- a: _Number, decimals: int = ..., out: Optional[ndarray] = ...
-) -> _Number: ...
-@overload
-def around(
- a: _NumberLike, decimals: int = ..., out: Optional[ndarray] = ...
-) -> number: ...
-@overload
-def around(
- a: ArrayLike, decimals: int = ..., out: Optional[ndarray] = ...
-) -> ndarray: ...
-@overload
-def mean(
- a: ArrayLike,
- axis: None = ...,
- dtype: DtypeLike = ...,
- out: None = ...,
- keepdims: Literal[False] = ...,
-) -> number: ...
-@overload
-def mean(
- a: ArrayLike,
- axis: Optional[_ShapeLike] = ...,
- dtype: DtypeLike = ...,
- out: Optional[ndarray] = ...,
- keepdims: bool = ...,
-) -> Union[number, ndarray]: ...
-@overload
-def std(
- a: ArrayLike,
- axis: None = ...,
- dtype: DtypeLike = ...,
- out: None = ...,
- ddof: int = ...,
- keepdims: Literal[False] = ...,
-) -> number: ...
-@overload
-def std(
- a: ArrayLike,
- axis: Optional[_ShapeLike] = ...,
- dtype: DtypeLike = ...,
- out: Optional[ndarray] = ...,
- ddof: int = ...,
- keepdims: bool = ...,
-) -> Union[number, ndarray]: ...
-@overload
-def var(
- a: ArrayLike,
- axis: None = ...,
- dtype: DtypeLike = ...,
- out: None = ...,
- ddof: int = ...,
- keepdims: Literal[False] = ...,
-) -> number: ...
-@overload
-def var(
- a: ArrayLike,
- axis: Optional[_ShapeLike] = ...,
- dtype: DtypeLike = ...,
- out: Optional[ndarray] = ...,
- ddof: int = ...,
- keepdims: bool = ...,
-) -> Union[number, ndarray]: ...
diff --git a/numpy/core/fromnumeric.pyi b/numpy/core/fromnumeric.pyi
new file mode 100644
index 000000000..7ad772b07
--- /dev/null
+++ b/numpy/core/fromnumeric.pyi
@@ -0,0 +1,492 @@
+import sys
+import datetime as dt
+from typing import Optional, Union, Sequence, Tuple, Any, overload, TypeVar
+
+from numpy import (
+ ndarray,
+ number,
+ integer,
+ bool_,
+ generic,
+ _OrderKACF,
+ _OrderACF,
+ _IntLike,
+ _BoolLike,
+ _NumberLike,
+)
+from numpy.typing import DtypeLike, ArrayLike, _ShapeLike, _Shape
+
+if sys.version_info >= (3, 8):
+ from typing import Literal
+else:
+ from typing_extensions import Literal
+
+_Mode = Literal["raise", "wrap", "clip"]
+_PartitionKind = Literal["introselect"]
+_SortKind = Literal["quicksort", "mergesort", "heapsort", "stable"]
+_Side = Literal["left", "right"]
+
+# Various annotations for scalars
+
+# While dt.datetime and dt.timedelta are not technically part of NumPy,
+# they are one of the rare few builtin scalars which serve as valid return types.
+# See https://github.com/numpy/numpy-stubs/pull/67#discussion_r412604113.
+_ScalarNumpy = Union[generic, dt.datetime, dt.timedelta]
+_ScalarBuiltin = Union[str, bytes, dt.date, dt.timedelta, bool, int, float, complex]
+_Scalar = Union[_ScalarBuiltin, _ScalarNumpy]
+
+# Integers and booleans can generally be used interchangeably
+_ScalarIntOrBool = TypeVar("_ScalarIntOrBool", bound=Union[integer, bool_])
+_ScalarGeneric = TypeVar("_ScalarGeneric", bound=generic)
+_ScalarGenericDT = TypeVar(
+ "_ScalarGenericDT", bound=Union[dt.datetime, dt.timedelta, generic]
+)
+
+_Number = TypeVar("_Number", bound=number)
+
+# An array-like object consisting of integers
+_IntOrBool = Union[_IntLike, _BoolLike]
+_ArrayLikeIntNested = ArrayLike # TODO: wait for support for recursive types
+_ArrayLikeBoolNested = ArrayLike # TODO: wait for support for recursive types
+
+# Integers and booleans can generally be used interchangeably
+_ArrayLikeIntOrBool = Union[
+ _IntOrBool,
+ ndarray,
+ Sequence[_IntOrBool],
+ Sequence[_ArrayLikeIntNested],
+ Sequence[_ArrayLikeBoolNested],
+]
+_ArrayLikeBool = Union[_BoolLike, Sequence[_BoolLike], ndarray]
+
+# The signature of take() follows a common theme with its overloads:
+# 1. A generic comes in; the same generic comes out
+# 2. A scalar comes in; a generic comes out
+# 3. An array-like object comes in; some keyword ensures that a generic comes out
+# 4. An array-like object comes in; an ndarray or generic comes out
+@overload
+def take(
+ a: _ScalarGenericDT,
+ indices: int,
+ axis: Optional[int] = ...,
+ out: Optional[ndarray] = ...,
+ mode: _Mode = ...,
+) -> _ScalarGenericDT: ...
+@overload
+def take(
+ a: _Scalar,
+ indices: int,
+ axis: Optional[int] = ...,
+ out: Optional[ndarray] = ...,
+ mode: _Mode = ...,
+) -> _ScalarNumpy: ...
+@overload
+def take(
+ a: ArrayLike,
+ indices: int,
+ axis: Optional[int] = ...,
+ out: Optional[ndarray] = ...,
+ mode: _Mode = ...,
+) -> _ScalarNumpy: ...
+@overload
+def take(
+ a: ArrayLike,
+ indices: _ArrayLikeIntOrBool,
+ axis: Optional[int] = ...,
+ out: Optional[ndarray] = ...,
+ mode: _Mode = ...,
+) -> Union[_ScalarNumpy, ndarray]: ...
+def reshape(a: ArrayLike, newshape: _ShapeLike, order: _OrderACF = ...) -> ndarray: ...
+@overload
+def choose(
+ a: _ScalarIntOrBool,
+ choices: ArrayLike,
+ out: Optional[ndarray] = ...,
+ mode: _Mode = ...,
+) -> _ScalarIntOrBool: ...
+@overload
+def choose(
+ a: _IntOrBool, choices: ArrayLike, out: Optional[ndarray] = ..., mode: _Mode = ...
+) -> Union[integer, bool_]: ...
+@overload
+def choose(
+ a: _ArrayLikeIntOrBool,
+ choices: ArrayLike,
+ out: Optional[ndarray] = ...,
+ mode: _Mode = ...,
+) -> ndarray: ...
+def repeat(
+ a: ArrayLike, repeats: _ArrayLikeIntOrBool, axis: Optional[int] = ...
+) -> ndarray: ...
+def put(
+ a: ndarray, ind: _ArrayLikeIntOrBool, v: ArrayLike, mode: _Mode = ...
+) -> None: ...
+def swapaxes(a: ArrayLike, axis1: int, axis2: int) -> ndarray: ...
+def transpose(
+ a: ArrayLike, axes: Union[None, Sequence[int], ndarray] = ...
+) -> ndarray: ...
+def partition(
+ a: ArrayLike,
+ kth: _ArrayLikeIntOrBool,
+ axis: Optional[int] = ...,
+ kind: _PartitionKind = ...,
+ order: Union[None, str, Sequence[str]] = ...,
+) -> ndarray: ...
+@overload
+def argpartition(
+ a: generic,
+ kth: _ArrayLikeIntOrBool,
+ axis: Optional[int] = ...,
+ kind: _PartitionKind = ...,
+ order: Union[None, str, Sequence[str]] = ...,
+) -> integer: ...
+@overload
+def argpartition(
+ a: _ScalarBuiltin,
+ kth: _ArrayLikeIntOrBool,
+ axis: Optional[int] = ...,
+ kind: _PartitionKind = ...,
+ order: Union[None, str, Sequence[str]] = ...,
+) -> ndarray: ...
+@overload
+def argpartition(
+ a: ArrayLike,
+ kth: _ArrayLikeIntOrBool,
+ axis: Optional[int] = ...,
+ kind: _PartitionKind = ...,
+ order: Union[None, str, Sequence[str]] = ...,
+) -> ndarray: ...
+def sort(
+ a: ArrayLike,
+ axis: Optional[int] = ...,
+ kind: Optional[_SortKind] = ...,
+ order: Union[None, str, Sequence[str]] = ...,
+) -> ndarray: ...
+def argsort(
+ a: ArrayLike,
+ axis: Optional[int] = ...,
+ kind: Optional[_SortKind] = ...,
+ order: Union[None, str, Sequence[str]] = ...,
+) -> ndarray: ...
+@overload
+def argmax(a: ArrayLike, axis: None = ..., out: Optional[ndarray] = ...) -> integer: ...
+@overload
+def argmax(
+ a: ArrayLike, axis: int = ..., out: Optional[ndarray] = ...
+) -> Union[integer, ndarray]: ...
+@overload
+def argmin(a: ArrayLike, axis: None = ..., out: Optional[ndarray] = ...) -> integer: ...
+@overload
+def argmin(
+ a: ArrayLike, axis: int = ..., out: Optional[ndarray] = ...
+) -> Union[integer, ndarray]: ...
+@overload
+def searchsorted(
+ a: ArrayLike,
+ v: _Scalar,
+ side: _Side = ...,
+ sorter: Optional[_ArrayLikeIntOrBool] = ..., # 1D int array
+) -> integer: ...
+@overload
+def searchsorted(
+ a: ArrayLike,
+ v: ArrayLike,
+ side: _Side = ...,
+ sorter: Optional[_ArrayLikeIntOrBool] = ..., # 1D int array
+) -> ndarray: ...
+def resize(a: ArrayLike, new_shape: _ShapeLike) -> ndarray: ...
+@overload
+def squeeze(a: _ScalarGeneric, axis: Optional[_ShapeLike] = ...) -> _ScalarGeneric: ...
+@overload
+def squeeze(a: ArrayLike, axis: Optional[_ShapeLike] = ...) -> ndarray: ...
+def diagonal(
+ a: ArrayLike, offset: int = ..., axis1: int = ..., axis2: int = ... # >= 2D array
+) -> ndarray: ...
+def trace(
+ a: ArrayLike, # >= 2D array
+ offset: int = ...,
+ axis1: int = ...,
+ axis2: int = ...,
+ dtype: DtypeLike = ...,
+ out: Optional[ndarray] = ...,
+) -> Union[number, ndarray]: ...
+def ravel(a: ArrayLike, order: _OrderKACF = ...) -> ndarray: ...
+def nonzero(a: ArrayLike) -> Tuple[ndarray, ...]: ...
+def shape(a: ArrayLike) -> _Shape: ...
+def compress(
+ condition: ArrayLike, # 1D bool array
+ a: ArrayLike,
+ axis: Optional[int] = ...,
+ out: Optional[ndarray] = ...,
+) -> ndarray: ...
+@overload
+def clip(
+ a: _Number,
+ a_min: ArrayLike,
+ a_max: Optional[ArrayLike],
+ out: Optional[ndarray] = ...,
+ **kwargs: Any,
+) -> _Number: ...
+@overload
+def clip(
+ a: _Number,
+ a_min: None,
+ a_max: ArrayLike,
+ out: Optional[ndarray] = ...,
+ **kwargs: Any,
+) -> _Number: ...
+@overload
+def clip(
+ a: ArrayLike,
+ a_min: ArrayLike,
+ a_max: Optional[ArrayLike],
+ out: Optional[ndarray] = ...,
+ **kwargs: Any,
+) -> Union[number, ndarray]: ...
+@overload
+def clip(
+ a: ArrayLike,
+ a_min: None,
+ a_max: ArrayLike,
+ out: Optional[ndarray] = ...,
+ **kwargs: Any,
+) -> Union[number, ndarray]: ...
+@overload
+def sum(
+ a: _Number,
+ axis: Optional[_ShapeLike] = ...,
+ dtype: DtypeLike = ...,
+ out: Optional[ndarray] = ...,
+ keepdims: bool = ...,
+ initial: _NumberLike = ...,
+ where: _ArrayLikeBool = ...,
+) -> _Number: ...
+@overload
+def sum(
+ a: ArrayLike,
+ axis: _ShapeLike = ...,
+ dtype: DtypeLike = ...,
+ out: Optional[ndarray] = ...,
+ keepdims: bool = ...,
+ initial: _NumberLike = ...,
+ where: _ArrayLikeBool = ...,
+) -> Union[number, ndarray]: ...
+@overload
+def all(
+ a: ArrayLike,
+ axis: None = ...,
+ out: Optional[ndarray] = ...,
+ keepdims: Literal[False] = ...,
+) -> bool_: ...
+@overload
+def all(
+ a: ArrayLike,
+ axis: Optional[_ShapeLike] = ...,
+ out: Optional[ndarray] = ...,
+ keepdims: bool = ...,
+) -> Union[bool_, ndarray]: ...
+@overload
+def any(
+ a: ArrayLike,
+ axis: None = ...,
+ out: Optional[ndarray] = ...,
+ keepdims: Literal[False] = ...,
+) -> bool_: ...
+@overload
+def any(
+ a: ArrayLike,
+ axis: Optional[_ShapeLike] = ...,
+ out: Optional[ndarray] = ...,
+ keepdims: bool = ...,
+) -> Union[bool_, ndarray]: ...
+def cumsum(
+ a: ArrayLike,
+ axis: Optional[int] = ...,
+ dtype: DtypeLike = ...,
+ out: Optional[ndarray] = ...,
+) -> ndarray: ...
+@overload
+def ptp(
+ a: _Number,
+ axis: Optional[_ShapeLike] = ...,
+ out: Optional[ndarray] = ...,
+ keepdims: bool = ...,
+) -> _Number: ...
+@overload
+def ptp(
+ a: ArrayLike,
+ axis: None = ...,
+ out: Optional[ndarray] = ...,
+ keepdims: Literal[False] = ...,
+) -> number: ...
+@overload
+def ptp(
+ a: ArrayLike,
+ axis: Optional[_ShapeLike] = ...,
+ out: Optional[ndarray] = ...,
+ keepdims: bool = ...,
+) -> Union[number, ndarray]: ...
+@overload
+def amax(
+ a: _Number,
+ axis: Optional[_ShapeLike] = ...,
+ out: Optional[ndarray] = ...,
+ keepdims: bool = ...,
+ initial: _NumberLike = ...,
+ where: _ArrayLikeBool = ...,
+) -> _Number: ...
+@overload
+def amax(
+ a: ArrayLike,
+ axis: None = ...,
+ out: Optional[ndarray] = ...,
+ keepdims: Literal[False] = ...,
+ initial: _NumberLike = ...,
+ where: _ArrayLikeBool = ...,
+) -> number: ...
+@overload
+def amax(
+ a: ArrayLike,
+ axis: Optional[_ShapeLike] = ...,
+ out: Optional[ndarray] = ...,
+ keepdims: bool = ...,
+ initial: _NumberLike = ...,
+ where: _ArrayLikeBool = ...,
+) -> Union[number, ndarray]: ...
+@overload
+def amin(
+ a: _Number,
+ axis: Optional[_ShapeLike] = ...,
+ out: Optional[ndarray] = ...,
+ keepdims: bool = ...,
+ initial: _NumberLike = ...,
+ where: _ArrayLikeBool = ...,
+) -> _Number: ...
+@overload
+def amin(
+ a: ArrayLike,
+ axis: None = ...,
+ out: Optional[ndarray] = ...,
+ keepdims: Literal[False] = ...,
+ initial: _NumberLike = ...,
+ where: _ArrayLikeBool = ...,
+) -> number: ...
+@overload
+def amin(
+ a: ArrayLike,
+ axis: Optional[_ShapeLike] = ...,
+ out: Optional[ndarray] = ...,
+ keepdims: bool = ...,
+ initial: _NumberLike = ...,
+ where: _ArrayLikeBool = ...,
+) -> Union[number, ndarray]: ...
+
+# TODO: `np.prod()``: For object arrays `initial` does not necessarily
+# have to be a numerical scalar.
+# The only requirement is that it is compatible
+# with the `.__mul__()` method(s) of the passed array's elements.
+
+# Note that the same situation holds for all wrappers around
+# `np.ufunc.reduce`, e.g. `np.sum()` (`.__add__()`).
+@overload
+def prod(
+ a: _Number,
+ axis: Optional[_ShapeLike] = ...,
+ dtype: DtypeLike = ...,
+ out: None = ...,
+ keepdims: bool = ...,
+ initial: _NumberLike = ...,
+ where: _ArrayLikeBool = ...,
+) -> _Number: ...
+@overload
+def prod(
+ a: ArrayLike,
+ axis: None = ...,
+ dtype: DtypeLike = ...,
+ out: None = ...,
+ keepdims: Literal[False] = ...,
+ initial: _NumberLike = ...,
+ where: _ArrayLikeBool = ...,
+) -> number: ...
+@overload
+def prod(
+ a: ArrayLike,
+ axis: Optional[_ShapeLike] = ...,
+ dtype: DtypeLike = ...,
+ out: Optional[ndarray] = ...,
+ keepdims: bool = ...,
+ initial: _NumberLike = ...,
+ where: _ArrayLikeBool = ...,
+) -> Union[number, ndarray]: ...
+def cumprod(
+ a: ArrayLike,
+ axis: Optional[int] = ...,
+ dtype: DtypeLike = ...,
+ out: Optional[ndarray] = ...,
+) -> ndarray: ...
+def ndim(a: ArrayLike) -> int: ...
+def size(a: ArrayLike, axis: Optional[int] = ...) -> int: ...
+@overload
+def around(
+ a: _Number, decimals: int = ..., out: Optional[ndarray] = ...
+) -> _Number: ...
+@overload
+def around(
+ a: _NumberLike, decimals: int = ..., out: Optional[ndarray] = ...
+) -> number: ...
+@overload
+def around(
+ a: ArrayLike, decimals: int = ..., out: Optional[ndarray] = ...
+) -> ndarray: ...
+@overload
+def mean(
+ a: ArrayLike,
+ axis: None = ...,
+ dtype: DtypeLike = ...,
+ out: None = ...,
+ keepdims: Literal[False] = ...,
+) -> number: ...
+@overload
+def mean(
+ a: ArrayLike,
+ axis: Optional[_ShapeLike] = ...,
+ dtype: DtypeLike = ...,
+ out: Optional[ndarray] = ...,
+ keepdims: bool = ...,
+) -> Union[number, ndarray]: ...
+@overload
+def std(
+ a: ArrayLike,
+ axis: None = ...,
+ dtype: DtypeLike = ...,
+ out: None = ...,
+ ddof: int = ...,
+ keepdims: Literal[False] = ...,
+) -> number: ...
+@overload
+def std(
+ a: ArrayLike,
+ axis: Optional[_ShapeLike] = ...,
+ dtype: DtypeLike = ...,
+ out: Optional[ndarray] = ...,
+ ddof: int = ...,
+ keepdims: bool = ...,
+) -> Union[number, ndarray]: ...
+@overload
+def var(
+ a: ArrayLike,
+ axis: None = ...,
+ dtype: DtypeLike = ...,
+ out: None = ...,
+ ddof: int = ...,
+ keepdims: Literal[False] = ...,
+) -> number: ...
+@overload
+def var(
+ a: ArrayLike,
+ axis: Optional[_ShapeLike] = ...,
+ dtype: DtypeLike = ...,
+ out: Optional[ndarray] = ...,
+ ddof: int = ...,
+ keepdims: bool = ...,
+) -> Union[number, ndarray]: ...