Ragged array library, complying with Python API specification.
Maintained. Last release 6 months ago, commits in 5 of the last 26 weeks. Weaker on commit activity and release cadence.
pip install raggedIntroduction
Ragged is a library for manipulating ragged arrays as though they were NumPy or CuPy arrays, following the Array API specification.
For example, this is a ragged/jagged array:
>>> import ragged
>>> a = ragged.array([[[1.1, 2.2, 3.3], []], [[4.4]], [], [[5.5, 6.6, 7.7, 8.8], [9.9]]])
>>> a
ragged.array([
[[1.1, 2.2, 3.3], []],
[[4.4]],
[],
[[5.5, 6.6, 7.7, 8.8], [9.9]]
])
The values are all floating-point numbers, so a.dtype is float64,
>>> a.dtype
dtype('float64')
but a.shape has non-integer dimensions to account for the fact that some of
its list lengths are non-uniform:
>>> a.shape
(4, None, None)
In general, a ragged.array can have any mixture of regular and irregular
dimensions, though shape[0] (the length) is always an integer. This convention
follows the Array API's specification for
array.shape,
which must be a tuple of int or None:
array.shape: Tuple[Optional[int], ...]
(Our use of None to indicate a dimension without a single-valued size differs
from the 's intention of specifying dimensions of size,
but it follows the technical specification. -consuming libraries
can try using to find out if they are ragged-ready.)