Julia-style arrays in Python
Project description
julialg
Julia-style arrays in Python
Python library for mimicking Julia LinearAlgebra array indexing style and display formatting.
Motivation and Summary
Julia's LinearAlgebra
package has some nice features, some of which are easier to emulate in Python than others. When
comparing the results of Python code vs Julia code, it is annoying to have to mentally switch between the 0-indexed nature of
Python and the 1-indexed nature of Julia. Also, the Julia arrays have a prettier array.
This package wraps numpy n-dimensional arrays in a new class, JulArray
, and allows for 1-indexed slicing (more mathematically intuitive)
instead of 0-indexed slicing (computer science convention). Also improves the prettiness of the representation of the
array in a manner similar to Julia's LinearAlgebra package. To be clear, this is a Python package, meant to bring some
of the elegance of Julia's interface for tensors to the Python setting
Indexing
The JulArray
class wraps a numpy.ndarray
but overrides the getitem syntax to allow for 1-indexed style instead of
the default 0-indexed style. For example:
>>> import numpy, julialg
# Create a numpy array
>>> a = numpy.arange(1, 11).reshape((2, 5))
# Create a JulArray from the numpy array
>>> j = julialg.JulArray(a)
# Index the numpy array using 0-indexed syntax
>>> a[0, 0:2]
array([1, 2])
# Index the JulArray using 1-indexed syntax
>>> j[1, 1:3].array
array([1, 2])
Notice in the above sample that the JulArray
is able to convert both ints and slices from 1-indexed notation to
0-indexed notation to produce the same underlying numpy array.
Display
The JulArray
overrides the default representation of the numpy array to be more cleanly formatted (like Julia arrays).
>>> julialg.JulArray(numpy.arange(1.0, 11.0).reshape((2, 5)))
2x5 Array{float64,2}
1.0000 6.0000
2.0000 7.0000
3.0000 8.0000
4.0000 9.0000
5.0000 10.0000
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file julialg-0.1.0.tar.gz
.
File metadata
- Download URL: julialg-0.1.0.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75ff8104b307d5702000344175263e347606c396fbc7cf507c03dd6472bda6d1 |
|
MD5 | 03778338c1be84cad1d50b6f86f02e81 |
|
BLAKE2b-256 | 19b3a22b77de91be767f7b28b5e1ad1b3d2a3f1c981eefc1d77399110cd92aa7 |
File details
Details for the file julialg-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: julialg-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72a8733d95b4facb652fd5fe0cce47d40952671b3cc7bc067ec4404ed6738efb |
|
MD5 | 62155d4e701952f92822d033dd695d35 |
|
BLAKE2b-256 | aec186f0a2f94e94e9977ec28803e5c5e4457f8f8adb3e7809796cb2a304dd24 |