serial_index_mapper#
- pybear.utilities.serial_index_mapper(shape, positions)#
Map serial index positions to their zero-based Cartesian coordinates in an object of the given shape.
- For example in a 2D array of shape (3,3):
serial index position 1 maps to (0,1)
serial index position 5 maps to (1,2)
- In a 3D array of shape (2,2,2):
serial index position 5 maps to (1, 0, 1)
- Parameters:
- shapeSequence[int, …]
The dimensions of the object to map into.
- positionsSequence[int]
Vector of serialized index positions.
- Returns:
- coordinateslist[tuple[int, …]]
The zero-based Cartesian coordinates for each given serialized index position.
Examples
>>> from pybear.utilities import serial_index_mapper >>> shape = (3,3,3) >>> positions = [4, 15, 25] >>> coordinates = serial_index_mapper(shape, positions) >>> print(coordinates) [(0, 1, 1), (1, 2, 0), (2, 2, 1)]