Skip to main content

Utils for indexing arrays with {-n, -(n-1), ..., -1, 0, 1, ..., n-1, n} using array API.

Project description

Array API Negative Index

CI Status Documentation Status Test coverage percentage

uv Ruff pre-commit

PyPI Version Supported Python versions License


Documentation: https://array-api-negative-index.readthedocs.io

Source Code: https://github.com/34j/array-api-negative-index


Utils for indexing arrays with {-n, -(n-1), ..., -1, 0, 1, ..., n-1, n} using array API.

Installation

Install this via pip (or your favourite package manager):

pip install array-api-negative-index

Usage

  • This package provides a utility for packing array elements in the order [0, 1, 2, ..., n, -n, ..., -2, -1].
  • This allows one to access the i-th element by array[i], regardless of whether i is positive, 0 or negative, thanks to "Negative Indexing" in array API.
  • This is useful for representing the order m in spherical harmonics for example.
from array_api_negative_index import to_symmetric, flip_symmetric, arange_asymmetric

arange_asymmetric()

import numpy as np

a = arange_asymmetric(3, xp=np)
print(a)
[ 0  1  2 -2 -1]

Not to confuse with np.arange(-stop + 1, stop)! This caused me to create bugs many times.

a = np.arange(-2, 3)
print(a)
[-2, -1, 0, 1, 2]

flip_symmetric()

b = flip_symmetric(a)
print(f"{a} -> (flip) -> {b}")
[ 0  1  2 -2 -1] -> (flip) -> [ 0 -1 -2  2  1]

to_symmetric()

c = np.asarray([0, 3, 5])
d = to_symmetric(c, asymmetric=True, conjugate=False)
print(f"{c} -> (to_symmetric) -> {d}")
[0 3 5] -> (to_symmetric) -> [ 0  3  5 -5 -3]

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

Credits

Copier

This package was created with Copier and the browniebroke/pypackage-template project template.

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

array_api_negative_index-1.0.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

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

array_api_negative_index-1.0.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file array_api_negative_index-1.0.0.tar.gz.

File metadata

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

File hashes

Hashes for array_api_negative_index-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e0f3c4a82b4de03b2d63d916fa26351979b34c713708e95b66f1cea7f7862d1a
MD5 143d8fe4ec017549c4e104be8e5e0ab5
BLAKE2b-256 2969ebd4846c11deb06e45fb3720f6f4c39be83e8d4a781f89fd3e839782f521

See more details on using hashes here.

Provenance

The following attestation bundles were made for array_api_negative_index-1.0.0.tar.gz:

Publisher: ci.yml on 34j/array-api-negative-index

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

File details

Details for the file array_api_negative_index-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for array_api_negative_index-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3728ce1d24822a559dbe9a2f68c2131803877d261ce680cbe8e5865860c08f1e
MD5 a3366e75890285cb724a01cd8a3e9091
BLAKE2b-256 90f697b52cbcd3fce6d46cc55f3dddc52700d3e1db1ada36d82456a6d59f1649

See more details on using hashes here.

Provenance

The following attestation bundles were made for array_api_negative_index-1.0.0-py3-none-any.whl:

Publisher: ci.yml on 34j/array-api-negative-index

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