allisbns.rearrange

Rearranges bins to binned images in various ways.

allisbns.rearrange.rearrange_to_rows(bins: ArrayLike, bin_size: int, width: int, pad_value: int = 0) ndarray[tuple[Any, ...], dtype[_ScalarT]]

Rearranges bins into rows with a fixed width.

Parameters:
  • bins – An array of bins.

  • bin_size – A size of bins.

  • width – A width of rows.

  • pad_value – A value used to fill the remaining space of the final row (when the number of bins is not divisible by width).

Returns:

Bins rearranged to rows with shape (height, row width).

Example

Here is a fictitious example to demonstrate the filling order:

>>> from allisbns.dataset import BinnedArray
>>> binned = BinnedArray(range(8), bin_size=1)
>>> rearrange_to_rows(
...      binned, bin_size=binned.bin_size, width=5
... )
array([[0, 1, 2, 3, 4],
       [5, 6, 7, 0, 0]])
allisbns.rearrange.rearrange_to_blocks(bins: ArrayLike, bin_size: int, block_width: int = int(1e5), block_size: int = int(5e7)) ndarray[tuple[Any, ...], dtype[_ScalarT]]

Rearranges bins into blocks of fixed width and height.

The arrangement is inspired by the “bookshelf” space-filling curve [1], but we treat it in a simpler way. So, it is basically an equivalent to the line-filling curve as in rearranges_to_rows() with additional division into vertical blocks of the fixed size stacked horizontally afterwards.

Parameters:
  • bins – An array of bins.

  • bin_size – A size of bins.

  • block_width – A width of one block.

  • block_size – A number of ISBNs in one block.

  • pad_value – A value used to fill the remaining space of the final block (when the number of bins is not divisible by the block size).

Returns:

Bins rearranged into shape (block height, block width * block count).

References

  1. https://phiresky.github.io/blog/2025/visualizing-all-books-in-isbn-space/

Example

Here is a fictitious example to demonstrate the filling order:

>>> from allisbns.dataset import BinnedArray
>>> binned = BinnedArray(range(18), bin_size=1)
>>> rearrange_to_blocks(
...     binned, binned.bin_size, block_width=3, block_size=9
... )
BinnedArray([[ 0,  1,  2,  9, 10, 11],
             [ 3,  4,  5, 12, 13, 14],
             [ 6,  7,  8, 15, 16, 17]])