Skip to main content

A NumPy-compatible array that ensures shape safety and prevents silent.errors.

Project description

ndsafe

A NumPy-compatible array that ensures shape safety and prevents silent errors.

Why ndsafe?

NumPy operations behave differently depending on whether an array is 1D ((n,)) or 2D ((m, n)). This can lead to unexpected errors in operations like:

  • Matrix multiplication (@)
  • Dot product (np.dot)
  • Transpose (.T)

ndsafe eliminates these issues by:

Automatically reshaping 1D arrays to 2D when needed

Ensuring reduction operations (sum, mean, etc.) remain efficient

Preventing silent shape mismatches in mathematical operations

Installation

pip install ndsafe

Usage

import numpy as np
from ndsafe import ndsafearray

# Avoid silent errors with matrix operations
a = ndsafearray([1, 2, 3])
b = ndsafearray([[4], [5], [6]])

print(a @ b)  # No more unexpected shape errors!

Key Features

  • Shape Safety: Converts (n,) → (1, n) where needed
  • Reduction Optimizations: Converts (1, n) → (n,) for efficiency
  • Seamless NumPy Interop: Works with np.sum(), np.dot(), etc.
  • Consistent Type Handling: Always returns ndsafearray unless a scalar

License

MIT License © Lucian Ursu

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

ndsafe-0.1.0.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

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

ndsafe-0.1.0-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file ndsafe-0.1.0.tar.gz.

File metadata

  • Download URL: ndsafe-0.1.0.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.6 Darwin/24.3.0

File hashes

Hashes for ndsafe-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e99e199afbace29c20e626b755268843164b0d8fa50c5fe08702a1f6083ff057
MD5 e745243c37cbaee8b7f9352ecef18c5f
BLAKE2b-256 b57ad138806266b10b2e892a98fd3192396340e020d3905e37bfd77229d3ea7e

See more details on using hashes here.

File details

Details for the file ndsafe-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ndsafe-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.6 Darwin/24.3.0

File hashes

Hashes for ndsafe-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d32ef13bd5c003fb0e793e7639f0cf6047d3d7a31d363078cc2ce72766868bc0
MD5 2591dece1ae65d1269affe3359fea19e
BLAKE2b-256 85d43d4efff3bce8d0f09c403f11cafd2d50681b0c2278feccda319e750cc266

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