numpy-hilbert-curve
This is a numpy-based implementation of Hilbert curves, for up to a few tens of dimensions. A Hilbert curve is a continuous space-filling curve that lets you map from a single dimension into multiple dimensions. In two dimensions, you get curves that look like this:
In three dimensions, you get curves that look like this:
This is working entirely in terms of integers, so the size of the (hyper-) cube reflects the number of bits per dimension. You could normalize this to put it into the unit hypercube with floating point numbers.
The mechanics of the implementation rely on the Gray-code "correction" procedure presented in
Skilling, J. (2004, April). Programming the Hilbert curve. In AIP Conference Proceedings (Vol. 707, No. 1, pp. 381-387). American Institute of Physics.
This paper does a lot of bit twiddling in C. I replicate this with "bool-twiddling" in numpy, but of course numpy represents a bool value with 8 bits, so don't expect it to really have the same performance as the equivalent C code. However, my goal here (rather than write it in Cython) was to make it easy to integrate with code you're already writing in Python with numpy.
Installation
You can install this via PyPI:
$ pip install numpy-hilbert-curve
Usage
The basic usage looks like this:
import numpy as np
from hilbert import decode, encode
# Turn an ndarray of Hilber integers into locations.
# 2 is the number of dimensions, 3 is the number of bits per dimension
locs = decode(np.array([1,2,3]), 2, 3)
print(locs)
# prints [[0 1]
# [1 1]
# [1 0]]
# You can go the other way also, of course.
H = encode(locs, 2, 3)
print(H)
# prints array([1, 2, 3], dtype=uint64)
The reason things like Hilbert curves are interesting is because they preserve some amount of locality. In this figure, I'm gradually changing the color in the Hilbert integers, using the "copper" colormap:
In this picture, I'm doing the same thing in 3d:
Metadata
Release files for numpy-hilbert-curve 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| numpy-hilbert-curve-1.0.1.tar.gz | 5.5 kB | Without provenance | Details for numpy-hilbert-curve-1.0.1.tar.gz |
Release files / numpy-hilbert-curve-1.0.1.tar.gz
| Download URL | numpy-hilbert-curve-1.0.1.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0745dbd4c16b258c180342d6df57dfa99110b9d98c86a84d920f29af5cc0707b
|
|
BLAKE2b-256 checksum How to use checksums |
cdbc49c9f728e12687720fa7785b0767c8c71e3fe7f275faa29dbbfc1d49cabb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5
|
Security for numpy-hilbert-curve 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.