I have the following logic operation coded in MATLAB, where [A, B, C, and D] are all 5x3x16 doubles and [a, b, c, and d] are all 240x1 doubles. I am trying to implement the same logic operation in python using numpy.
D = zeros(size(A));
for i = 1:numel(D)
flag = ...
(a == A(i)) & ...
(b == B(i)) & ...
(c == C(i));
D(i) = d(flag);
end
d is a column vector that is already populated with data. a, b, and c are also populated column vectors of equal size. Meshgrid was used to construct A, B, and C into a LxMxN grid of the unique values within a, b, and c. Now I want to use d to populate a LxMxN D with the appropriate values using the boolean expression.
I have tried:
D= np.zeros(np.shape(N))
for i in range(len(D)):
for j in range(len(D[0])):
for k in range(len(D[0][0])):
flag = np.logical_and(
(a == A[i][j][k]),
(b == B[i][j][k]),
(c == C[i][j][k])
)
D[i][j][k] = d[flag];