Skip to content

Instantly share code, notes, and snippets.

@mstankie
mstankie / grid_indices_list.py
Last active September 5, 2022 10:52
List of 3D grid indices in NumPy
# Get i, j, k indices of grid nodes as a list to iterate over
import numpy as np
GRID_SHAPE = (2, 3, 4)
grid_indices: np.ndarray = np.indices(GRID_SHAPE).reshape(len(GRID_SHAPE), -1).T
grid_indices.shape # >> (24, 3)
# This way we can loop through the indices as array rows
for idx in grid_indices: