python - Correspondence between a "ij" meshgrid and a long meshgrid -
Consider a matrix Z
which contains grid-based results for z = z Are, m, e).
Z
has the size (lane (aggregate), lane (mg), lane (eagrid))
. Contains Z [0,1,2]
in z (a = agrrid [0], m = mGrid [1], e = eagreement [2])
. However, we may have removed some elements of state space from the object (for example and simplicity, (a, m, e: a & gt; 3)
say the size of a valid state location x
.
I have a code to convert this object to the Z2
shape of (x, 3)
Each line in Z2
belongs to Z2
: (agrrid [a [i]], mGrid [m [I]], eGrid [e]]]
.
# first z, based on a mash grid Create tricks in which there are some invalid states (we set them to nan) 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 (aggregate, mizid, eagrid, indexing = 'ij') Z = aZ [z3] = NP.NAN # # Now, translate them by size (grid from lane (aggregate), lane (mgid), grid (eagrid) = [a, m, e] grid_bc = np.broadest_arriage (* grid) Z2 = NP column_stack (g.ravel for g for gr) grid_bc] Z2 [np.isna, through a few calculations, I then use a matrix V4
/ code> which contains the size of Z3
but has the 4 columns in it.
I have been given
-
Z2
(above) -
Z3
(As above) -
V4
which is the matrix shape (Z3.shape [0], Z3.shape [1] +1
): An extra column has been added to it - (if still needed, I still do
and grid me
-
V >
, which is the matrix in which the value ofV4
(in the last column), but it isZ1
That is, if in V4
Is a line that reads (aggregation [0], MGID [1], eigridge [2], v1), then
V
at V [0,1, 2] = v1
, for values of V4
for all the rows,
efficiency is important .
Given the status of your root problem, the form builds in the following form has been modified in such a manner that A
a copy of z
:
aGrid = np.arange (0, 10, dtype = float) mGrid = np .Range (100, 110, dtype = float) eGrid = np.arange (1000, 1200, dtype = float) A , M, E = np.meshgrid (agrid, mGrid, eGrid, indexing = 'ij') Z = A .copy () Z [Z & gt; 3] = np.NaN grid = [a, m, e] grid_bc = np.broadest_arriage (* grid) z2 = np. column_stack (g.ravel for gr for gr) grid_bc]) z2 [np.isnan (Z .Ravel ())] = np.nan z3 = z2 [~ np.isnan (z2)]
A function can be defined as follows, a dense ND matrix is defined as sparse 2 The first logic of the matrix function is the aformentioned 2D matrix, the last (optional) argument grid is indexed for each dimension:
# dims + 1
import dp map_array_ Numpy import as to_index (uniq_arr): return np.vectorize (digEX (napaar)) .__ getitem__) Def reconfiguration (ARI, * coordination): If lane (coordinates)! = Arr.shape [1] - 1: coordinate = map (NP.INIK, ARM [0: -1]) lookups = map (map_array_to_index, coord_arrays) new_array = np.nan * np.ones (map (lane, coordinate) ) New_array [Tupl (L) for Z, Z in ZIP (AR [0: -1], Lookup)]] = ARR [:, -1] New_Grids = N.P. Mashgrid (* Coordinate-systematic, Looking at the 2D matrix V4, the values derived from Z are defined above, Code> V4 = np.column_stack (grid_bc) For [g.ravel ()) + [Z.ravel ()])
It is possible to recreate Z as follows:
V4_orig_form, V4_grids = recreate (V4, agrid, mGrid, eGrid)
/ p again>Testing for all non-NaN values similarity:
np.all (Z [~ np.isnan (Z)] == V4_orig_form [~ np.isnan (V4_orig_form)]
Function Aggregation, MGIDD, even without Agrid But in this case there will not be any coordination which is not present in this column of input array.
Comments
Post a Comment