Skip to main content

Type hints for Numpy

Project description

Python versions PyPI version Build Status

nptyping

Type hints for Numpy!

Installation

pip install nptyping

Usage

Use the nptyping type hints like the regular type hints from typing:

from nptyping import Array


def func1(arr: Array[int]):  # A numpy.ndarray that contains numbers
    ...

You can also define the shape of an array:

Array[str, 3, 2]    # 3 rows and 2 columns
Array[str, 3]       # 3 rows and an undefined number of columns
Array[str, 3, ...]  # 3 rows and an undefined number of columns
Array[str, ..., 2]  # an undefined number of rows and 2 columns

Heterogeneous arrays are supported as well:

Array[int, float, str]       # int, float and str on columns 1, 2 and 3 resp.
Array[int, float, str, ...]  # int, float and str on columns 1, 2 and 3 resp.
Array[int, float, str, 3]    # 3 rows and int, float and str on columns 1, 2 and 3 resp.

nptyping also supports instance checks:

import numpy
from nptyping import Array


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

isinstance(arr, Array[int, 3, 2])    # True
isinstance(arr, Array[str, 3, 2])    # False
isinstance(arr, Array[int, 3, ...])  # True
isinstance(arr, Array[int, 3, 6])    # False

Also for heterogeneous arrays:

import numpy
from nptyping import Array


arr = np.array([(1, 2.0, '3'),
                (4, 5.0, '6')],
               dtype=[('a', int), ('b', float), ('c', str)])

isinstance(arr, Array[int, float, str])     # True
isinstance(arr, Array[float, float, str])   # False
isinstance(arr, Array[int, float, str, 2])  # True

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nptyping-0.3.0-py3-none-any.whl (1.8 kB view details)

Uploaded Python 3

File details

Details for the file nptyping-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: nptyping-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 1.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for nptyping-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c3ab1b840da7d2720e7cd76b8d478d66b43ef64b3d3a5e419ac112ec9bf1859e
MD5 4633151182b172183ec709460a50473a
BLAKE2b-256 5df0d949ae7d837f29a561e802295baa097a61e67a063c27bdf823920c5fd9e9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page