I have a very large numpy array that looks like this (first 5 entries):
[[ 1. 0.01 0.02 0.6 0.01 0.5 0.01 0.5 0.5 0.5 ]
[ 0.5 0.01 0.01 0.6 0.01 0.5 0.5 0.5 0.5 0.6 ]
[ 0.6 0.01 0.5 0.5 0.5 0.5 0.7 0.01 0.01 0. ]
[ 0.01 0.5 0.8 0.02 0.02 0.81 0.01 0.77 0.02 0.01]
[ 0.5 0.02 0.5 0. 0.5 0.5 0.01 0.6 0.01 0. ]]
I search this array for specific sequences that are also 10 values long. So I store the incoming sequences after no special rule, just 0 1 2 3 ... and the same I search this array. This is my search method (silo_arrays[][] is the array above, array_pattern[] is a 1D numpy 10 values long array for which I search the silo_arrays):
new_pattern=True
for z in range(0, self.silo_arrays_c):
eq_rate = 0
for y in range(0, self.length):
if(self.silo_arrays[z][y] != array_pattern[y]):
break
else:
eq_rate += 1
if(eq_rate == self.length):
new_pattern = False
break
This takes about 0.006257s if the silo_arrays is something like 1585 entries long. Has anyone ideas on how to accelerate this search process by some kind of sorting or structural changes? Thank you for your support :)
np.where((silo_arrays==array_pattern).all(1))
? – Divakar Feb 17 '17 at 11:29