Skip to content Skip to sidebar Skip to footer

Translation Between Grid Index And Actual Values

I have a grid of shape (A1, M1, A2, M2, A3, M3, E) which I generated using A1, M1, A2, M2, A3, M3, E = meshgrid(Grid.aGrid, Grid.mGrid, Grid.aGrid, Grid.mGrid, Grid.aGrid, Grid.mGr

Solution 1:

Use broadcast_arrays(), and the result Z2 is an array with shape (20000, 3).

import numpy as np

aGrid = np.arange(0, 10, dtype=float)
mGrid = np.arange(100, 110, dtype=float)
eGrid = np.arange(1000, 1200, dtype=float)

A,M,E = np.meshgrid(aGrid, mGrid, eGrid, indexing='ij')

# contains the grid index
Z = (A + M + E).astype(float)
Z[A < 3] = np.nan

grids = [A, M, E]
grid_bc = np.broadcast_arrays(*grids)
Z2 = np.column_stack([g.ravel() for g in grid_bc])
Z2[np.isnan(Z.ravel())] = np.nan

print Z2[5900], Z2[6000]

Post a Comment for "Translation Between Grid Index And Actual Values"