All Projects → ramonhagenaars → Nptyping

ramonhagenaars / Nptyping

Licence: mit
💡 Type hints for Numpy

Programming Languages

python
139335 projects - #7 most used programming language
python3
1442 projects

Labels

Projects that are alternatives of or similar to Nptyping

Amadia
Astus' Mathematical Display Application : A GUI for Mathematics (Calculator, LaTeX Converter, Plotter, ... )
Stars: ✭ 172 (-15.69%)
Mutual labels:  numpy
Rootpy
A pythonic interface for the ROOT libraries on top of the PyROOT bindings.
Stars: ✭ 186 (-8.82%)
Mutual labels:  numpy
Gluon Nlp
NLP made easy
Stars: ✭ 2,344 (+1049.02%)
Mutual labels:  numpy
Mars
Mars is a tensor-based unified framework for large-scale data computation which scales numpy, pandas, scikit-learn and Python functions.
Stars: ✭ 2,308 (+1031.37%)
Mutual labels:  numpy
Np ml
A tool library of classical machine learning algorithms with only numpy.
Stars: ✭ 180 (-11.76%)
Mutual labels:  numpy
Xtensor
C++ tensors with broadcasting and lazy computing
Stars: ✭ 2,453 (+1102.45%)
Mutual labels:  numpy
Psi4numpy
Combining Psi4 and Numpy for education and development.
Stars: ✭ 170 (-16.67%)
Mutual labels:  numpy
Alyn
Detect and fix skew in images containing text
Stars: ✭ 202 (-0.98%)
Mutual labels:  numpy
Tftb
A Python module for time-frequency analysis
Stars: ✭ 185 (-9.31%)
Mutual labels:  numpy
Data Science Notebook
📖 每一个伟大的思想和行动都有一个微不足道的开始
Stars: ✭ 196 (-3.92%)
Mutual labels:  numpy
Tensorflow Ml Nlp
텐서플로우와 머신러닝으로 시작하는 자연어처리(로지스틱회귀부터 트랜스포머 챗봇까지)
Stars: ✭ 176 (-13.73%)
Mutual labels:  numpy
Andrew Ng Notes
This is Andrew NG Coursera Handwritten Notes.
Stars: ✭ 180 (-11.76%)
Mutual labels:  numpy
Fashion Recommendation
A clothing retrieval and visual recommendation model for fashion images.
Stars: ✭ 193 (-5.39%)
Mutual labels:  numpy
Pyhf
pure-Python HistFactory implementation with tensors and autodiff
Stars: ✭ 171 (-16.18%)
Mutual labels:  numpy
Data Science Projects With Python
A Case Study Approach to Successful Data Science Projects Using Python, Pandas, and Scikit-Learn
Stars: ✭ 198 (-2.94%)
Mutual labels:  numpy
Ditching Excel For Python
Functionalities in Excel translated to Python
Stars: ✭ 172 (-15.69%)
Mutual labels:  numpy
Pyresample
Geospatial image resampling in Python
Stars: ✭ 188 (-7.84%)
Mutual labels:  numpy
Awkward 1.0
Manipulate JSON-like data with NumPy-like idioms.
Stars: ✭ 203 (-0.49%)
Mutual labels:  numpy
Python Novice Inflammation
Programming with Python
Stars: ✭ 199 (-2.45%)
Mutual labels:  numpy
Pybotics
The Python Toolbox for Robotics
Stars: ✭ 192 (-5.88%)
Mutual labels:  numpy

PyPI version Downloads PyPI version codecov Scrutinizer Code Quality

Type hints for Numpy!

(❒) Installation

pip install nptyping

(❒) Usage

(❒) NDArray

nptyping.NDArray lets you define the shape and type of your numpy.ndarray.

You can:

  • specify the number of dimensions;
  • specify the size per dimension;
  • specify the type of the array;
  • instance check your array with your nptying type.

(❒) Examples

An Array with any dimensions of any size and any type:

>>> from nptyping import NDArray
>>> from typing import Any


>>> NDArray
NDArray[(typing.Any, ...), typing.Any]

>>> NDArray[(Any, ...)]
NDArray[(typing.Any, ...), typing.Any]

>>> NDArray[(Any, ...), Any]
NDArray[(typing.Any, ...), typing.Any]

An array with 1 dimension of any size and any type:

>>> NDArray[Any]
NDArray[(typing.Any,), typing.Any]

>>> NDArray[(Any,)]
NDArray[(typing.Any,), typing.Any]

>>> NDArray[Any, Any]
NDArray[(typing.Any,), typing.Any]

>>> NDArray[(Any,), Any]
NDArray[(typing.Any,), typing.Any]

An array with 1 dimension of size 3 and any type:

>>> NDArray[3]
NDArray[(3,), typing.Any]

>>> NDArray[(3,)]
NDArray[(3,), typing.Any]

>>> NDArray[(3,), Any]
NDArray[(3,), typing.Any]

An array with 3 dimensions of size 3, 3 and any and any type:

>>> NDArray[3, 3, Any]
NDArray[(3, 3, typing.Any), typing.Any]

>>> NDArray[(3, 3, Any)]
NDArray[(3, 3, typing.Any), typing.Any]

>>> NDArray[(3, 3, Any), Any]
NDArray[(3, 3, typing.Any), typing.Any]

An array with any dimensions of any size and type int:

>>> import numpy as np

>>> NDArray[np.int32]
NDArray[(typing.Any, ...), Int[32]]

>>> NDArray[(Any, ...), np.int32]
NDArray[(typing.Any, ...), Int[32]]

Note that provided types are translated to nptyping types. Pure Python types (.e.g int or float are supported as well). You can also provide nptyping types yourself: NDArray[(Any, ...), Int[64]].

An array with 1 dimension of size 3 and type int:

>>> NDArray[3, np.int32]
NDArray[(3,), Int[32]]

>>> NDArray[(3,), np.int32]
NDArray[(3,), Int[32]]

An array with any dimensions of size 3 and type int:

>>> NDArray[(3, ...), np.int32]
NDArray[(3, ...), Int[32]]

An array with 3 dimensions of sizes 3, 3, 5 and type int:

>>> NDArray[(3, 3, 5), np.int32]
NDArray[(3, 3, 5), Int[32]]

A structured array:

>>> import numpy as np

>>> NDArray[(Any,...), np.dtype([('x',np.int32), ('y',np.int32)])]
NDArray[(typing.Any, ...), StructuredType[Int[32], Int[32]]]

(❒) Checking your instances

You can use NDArray with isinstance to dynamically check your arrays.

>>> import numpy as np

>>> arr = np.array([[1, 2, 3],
...                 [4, 5, 6]])

>>> isinstance(arr, NDArray[(2, 3), int])
True
>>> isinstance(arr, NDArray[(2, 3), float])
False
>>> isinstance(arr, NDArray[(2, 3, 1), int])
False

(❒) Finding the right annotation

You can use NDArray to find the type of a numpy array for you using NDArray.type_of:

>>> NDArray.type_of(np.array([[1, 2], [3, 4.0]]))
NDArray[(2, 2), Float[64]]

See also nptyping.get_type (documented below).

(❒) Int

An nptyping equivalent of numpy signed integers.

>>> from nptyping import Int

>>> Int[32]
Int[32]

You can also use one of these:

>>> from nptyping import Int8, Int16, Int32, Int64

(❒) UInt

An nptyping equivalent of numpy unsigned integers.

>>> from nptyping import UInt

>>> UInt[64]
UInt[64]

You can also use one of these:

>>> from nptyping import UInt8, UInt16, UInt32, UInt64

(❒) Float

An nptyping equivalent of numpy floats.

>>> from nptyping import Float

>>> Float[64]
Float[64]

You can also use one of these:

>>> from nptyping import Float16, Float32, Float64

(❒) Unicode

An nptyping equivalent of numpy unicodes.

>>> from nptyping import Unicode

>>> Unicode[100]
Unicode[100]

(❒) Bool

An nptyping equivalent of numpy bool.

>>> from nptyping import Bool

>>> Bool
Bool

(❒) Complex128

An nptyping equivalent of numpy complex128.

>>> from nptyping import Complex128

>>> Complex128
Complex128

(❒) Datetime64

An nptyping equivalent of numpy datetime64.

>>> from nptyping import Datetime64

>>> Datetime64
Datetime64

(❒) Timedelta64

An nptyping equivalent of numpy timedelta64.

>>> from nptyping import Timedelta64

>>> Timedelta64
Timedelta64

(❒) Object

An nptyping equivalent of numpy objects.

>>> from nptyping import Object

>>> Object
Object

(❒) StructuredType

An nptyping equivalent of numpy structured dtypes.

>>> from nptyping import StructuredType, Int

>>> StructuredType[Int[32], Int[32]]
StructuredType[Int[32], Int[32]]

(❒) SubArrayType

An nptyping equivalent of numpy subarray dtypes.

>>> from nptyping import SubArrayType, Int

>>> SubArrayType[Int[16], (4,2)]
SubArrayType[Int[16], (4, 2)]

(❒) get_type

With get_type you can get nptyping equivalent types for your arguments:

>>> from nptyping import get_type

>>> get_type(np.int32)
Int[32]
>>> get_type('some string')
Unicode[11]
>>> get_type(np.dtype([('x', np.int32), ('y', np.int32)]))
StructuredType[Int[32], Int[32]]

(❒) py_type

With py_type you can get the Python builtin type that corresponds to a Numpy dtype:

>>> from nptyping import py_type

>>> py_type(np.int32)
<class 'int'>

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].