Skip to main content

A library for checking the shapes of multidimensional arrays.

Project description

ndshapecheck

ndshapecheck is a simple library for checking the shape of numpy arrays. To get started, see the examples below. For more information, please visit the documentation.

Contributions are welcome! Please read the contribution guide for more information.

Quickstart

Requirements

  • Python 3.10 or newer

Installation

Install the library with:

pip install ndshapecheck

Basic Usage

Import the library:

from ndshapecheck import ShapeCheck

Create a ShapeCheck instance and verify shapes:

import numpy as np
sc = ShapeCheck()

assert sc('A,B,3').check(np.zeros(10, 10, 3)), sc.why # A = 10, B = 10
assert sc('A,C*,3').check(np.zeros(10, 3, 2, 3, 3)), sc.why # C*=3, 2, 3

Notes

  • Symbol Binding: ShapeCheck objects remember symbol values between checks.

    In the example above, the first call sets A=10 and B=10. Subsequent checks using these symbols will fail if a value other than 10 is found within the shape.

  • Shape Rules: Shape rules are comma-separated strings. Each element is either:

    • A non-negative integer (e.g. 3, 5)
    • A case-sensitive symbolic name (e.g. A, B1, my_dim)
  • Quantifiers: You can append standard regular expression quantifiers to symbols:

    • * : zero or more dimensions
    • + : one or more dimensions
    • ? : optional dimension
  • Important: A, A*, A? and A+ are treated as separate symbols. Example:

    sc('A*,A').check(np.zeros((5, 10, 10)))
    # Assigns A* = (5,10) and A = 10 separately
    
  • Important: If an optional symbol is omitted, it must also be omitted in future checks. Example:

    sc('optional_batch?,n_features').check((12,))  # no batch dimension
    sc('optional_batch?,n_labels').check((10, 3))  # fails. batch dimension should be omitted
    
  • Error Messages: If a shape check fails, sc.why contains a message string explaining why.

Project details


Download files

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

Source Distribution

ndshapecheck-0.2.2.tar.gz (42.4 kB view details)

Uploaded Source

Built Distribution

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

ndshapecheck-0.2.2-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file ndshapecheck-0.2.2.tar.gz.

File metadata

  • Download URL: ndshapecheck-0.2.2.tar.gz
  • Upload date:
  • Size: 42.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ndshapecheck-0.2.2.tar.gz
Algorithm Hash digest
SHA256 352873e60997e10b6c9bc968849b73549f262f50847c2a5adbe93ca2308ca917
MD5 3f50c85a4f08d4a6095de72bb2f892fb
BLAKE2b-256 5037474771450ae8a1f17a4d32ced3102828ec3ad263a4fab5d80ed98cec1ed7

See more details on using hashes here.

Provenance

The following attestation bundles were made for ndshapecheck-0.2.2.tar.gz:

Publisher: publish.yml on mrjoe3012/ndshapecheck

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ndshapecheck-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: ndshapecheck-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ndshapecheck-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b690ee55f7ba03a5ee5e44c0b4d3798cfbbd6b4deb6f3a4e0dc18f82abc3c6d0
MD5 ed006f2c1d94f8b0dd7e5ce6b036d45c
BLAKE2b-256 07b5a88cbea9d05eb78a037e8cb0ab23c8ca4205b21a46056dca1069ce282b93

See more details on using hashes here.

Provenance

The following attestation bundles were made for ndshapecheck-0.2.2-py3-none-any.whl:

Publisher: publish.yml on mrjoe3012/ndshapecheck

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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