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]{.title-ref} 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:
ShapeCheckobjects remember symbol values between checks.In the example above, the first call sets
A=10andB=10. Subsequent checks using these symbols will fail if a value other than10is 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)
- A non-negative integer (e.g.
-
Quantifiers: You can append standard regular expression quantifiers to symbols:
*: zero or more dimensions+: one or more dimensions?: optional dimension
-
Important:
A,A*,A?andA+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.whycontains 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ndshapecheck-0.2.0.tar.gz.
File metadata
- Download URL: ndshapecheck-0.2.0.tar.gz
- Upload date:
- Size: 42.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1420ef88b84eb7b77ecf0606f4894447df02339147f5ff57c02487d13a0087f4
|
|
| MD5 |
675c08ca33f3fa3d781c4e6d9e0098ad
|
|
| BLAKE2b-256 |
e9c930f11035e782b7f7e29f4a2f73997742e1ac5ccbe3e35b881fe129af093f
|
Provenance
The following attestation bundles were made for ndshapecheck-0.2.0.tar.gz:
Publisher:
publish.yml on mrjoe3012/ndshapecheck
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ndshapecheck-0.2.0.tar.gz -
Subject digest:
1420ef88b84eb7b77ecf0606f4894447df02339147f5ff57c02487d13a0087f4 - Sigstore transparency entry: 203172662
- Sigstore integration time:
-
Permalink:
mrjoe3012/ndshapecheck@08c508ece6a1c04253d5890812643709212d3be7 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/mrjoe3012
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@08c508ece6a1c04253d5890812643709212d3be7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ndshapecheck-0.2.0-py3-none-any.whl.
File metadata
- Download URL: ndshapecheck-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8251ebf3922c799a00c1c76a31150126998f1ec34a7f87cfdc210f44096388a
|
|
| MD5 |
8feec6dacfe679596ef3b3115b655155
|
|
| BLAKE2b-256 |
17e82545bb14335e55aa57a498e205b9e2dbc6e002aa471fe62952ba78d053ad
|
Provenance
The following attestation bundles were made for ndshapecheck-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on mrjoe3012/ndshapecheck
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ndshapecheck-0.2.0-py3-none-any.whl -
Subject digest:
a8251ebf3922c799a00c1c76a31150126998f1ec34a7f87cfdc210f44096388a - Sigstore transparency entry: 203172663
- Sigstore integration time:
-
Permalink:
mrjoe3012/ndshapecheck@08c508ece6a1c04253d5890812643709212d3be7 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/mrjoe3012
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@08c508ece6a1c04253d5890812643709212d3be7 -
Trigger Event:
push
-
Statement type: