Suppose you have few logical tables as follows:
import numpy as np
table1 = np.zeros((4,3)); table2 = np.zeros((4,3)); table3 = np.zeros((4,3));
table1[0] = 1; table2[1] = 1; table3[1] = table3[3] = 1;
Now suppose you have a set of arrays that change in shape during a simulation depending on certain conditions, let's call them equations:
eq1 =[[a,b,c], [d,e,f]]; eq2 = [[g,h,i],[j,k,l]]; eq3 = [[m,n,o],[p,q,r]];
#result array:
result = np.zeros((4,3))
The result array is a combination of the different equations assigned to different rows, using the logical tables as follows:
result = table1*eq1 + table2*eq2 + table3*eq3
In a way that the end result is something like this:
result = [[a,b,c], [g +m,h+n,i+o], [0,0,0], [p,q,r]];
I know the code above has issues because of the different shapes. And I also know how to solve this particular problem to multiply element wise two arrays. But my question is in the general case. The array result is changing dynamically in a simulation loop because the equations are changing. So is there a way to have a general solution for this? In a sense if you have the array table1 of shape (4,3) for example and another array say eq1 it could be (2,3), it could be (2,2), etc.. but always less than or equal the dimensions of table1. So how to do this multiplication of the two, such that the elements of table1 that are outside the range of eq1 stays the same. Think about the simulation this way:
for time_simulation:
Update(eq1,eq2,eq3)
result = table1*eq1 + table2*eq2 + table3*eq3
Use(result)
I hope my question is clear.