I have an example of a python code snippet. I need to check all the numbers from the map_spectrum array for 5 conditions, then put the new value in another array according to them. How can this be done in a more optimized version than in python code ?
x = y = np.arange(0.0, 1.0, 0.1)
map_spectrum = np.ones( (len(x), len(y), 6) )
map_color = np.ones( ( len(x), len(y) ) )
for ix, xv in enumerate(x):
for iy, yv in enumerate(y):
if map_spectrum[ix, iy, 0] > 0 and map_spectrum[ix, iy, 1] > 0 and map_spectrum[ix, iy, 2] == 0 and map_spectrum[ix, iy, 3:] < 0 :
map_color[ix, iy] = 1
In the real case, this array has a size of 101x101x6, that is, conditionally there are 10201 cells containing 6 values.
All the cases of conditions in a short form:
First case +, +, 0, -, -, -
Second case +, 0, -, - ,- ,-
Third case 0, 0, -, -, -, -
Four case 0, -, -, -
Another
In addition, how to take into account machine zero when checking conditions.
Example real values from array
After creating a new array, it will be used as colors in heatmap that is
heatmap(x, y, map_color)
I tried to cycle through all the values and check them for 5 conditions, but it takes quite a long time