Class np.typing
- Namespace
- NumSharp
- Assembly
- NumSharp.dll
numpy.typing — NumPy's static-typing aliases (NDArray, ArrayLike, DTypeLike,
NBitBase), each as the C# type that plays its role in NumSharp's own signatures.
[ModuleName("np.typing")]
public static class np.typing
- Inheritance
-
np.typing
- Inherited Members
Examples
// def mean_of(x: npt.ArrayLike, dtype: npt.DTypeLike = None) -> npt.NDArray[np.float64]: ...
static NDArray<double> mean_of(NDArray x, DType dtype = null) => ...;
Type t = np.typing.NDArray.MakeGenericType(typeof(double)); // typeof(NDArray<double>)
Remarks
Why the members are Type objects. NumPy's names are type ALIASES for annotations
(def f(x: npt.ArrayLike) -> npt.NDArray[np.float64]). C# has no exported type aliases — a property
cannot stand in a signature — so the type checker's role is the C# compiler's, and each alias already has a
C# type that NumSharp uses in its place everywhere. The members name those types, the way
np.dtypes names the dtype classes, so a program can look them up and a port knows what to write:
| NumPy annotation | C# type |
|---|---|
npt.NDArray[np.float64] | NDArray<double>
(NDArray is its generic definition, so np.typing.NDArray.MakeGenericType(typeof(double))
is typeof(NDArray<double>)); with an abstract or unknown scalar type
(npt.NDArray[np.floating], npt.NDArray[Any]) the untyped NDArray. |
npt.ArrayLike | NDArray (ArrayLike): every NumSharp
function takes its array_like arguments as NDArray, whose implicit conversions accept a scalar of
any dtype, a C# array of any rank (jagged too) and a string; np.asanyarray(object) converts the rest
of NumPy's array_like set (lists of objects, tuples, enumerables, Memory<T>). |
npt.DTypeLike | DType (DTypeLike): every
dtype= parameter, which accepts a DType, a C# Type, an NPTypeCode and a
dtype string implicitly; a scalar class (NDScalarType) converts explicitly. |
npt.NBitBase | np.typing.NBitBase: deprecated in NumPy 2.3, and without a use in C#, which has no precision-generic scalar classes. |
Properties
ArrayLike
numpy.typing.ArrayLike (objects that can be converted to arrays): NDArray, the type NumSharp
takes every array_like argument as. Its implicit conversions accept a scalar of any of the 15 dtypes, a C#
array of any rank or a jagged one, and a string; for the rest of NumPy's set (a list of objects, a tuple,
an enumerable) np.asanyarray(object) builds the array.
public static Type ArrayLike { get; }
Property Value
DTypeLike
numpy.typing.DTypeLike (objects that can be converted to dtypes): DType, the type of every
dtype= parameter. A DType, a C# Type (typeof(float)), an
NPTypeCode and a dtype string ("f4", "float32") all convert to it implicitly; a scalar
class converts explicitly ((DType)t), because an abstract one has no dtype.
public static Type DTypeLike { get; }
Property Value
NDArray
numpy.typing.NDArray (ndarray[tuple[Any, ...], dtype[ScalarT]]): the generic definition
NumSharp.Generic.NDArray<T>, NumSharp's array typed by its element type (it derives from the
untyped NumSharp.NDArray). npt.NDArray[np.float64] is NDArray<double>, i.e. this
type closed over the C# element type (NDArray.MakeGenericType(typeof(double))).
public static Type NDArray { get; }
Property Value
Remarks
Inside this class the name NDArray means this property, so the code spells NumSharp's array types
with global::.