How to compare two SArrays quickly?

User 3870 | 3/21/2016, 11:28:24 PM


I have two SArrays and would like to compare their similarity quickly. eg [1,2,3] with [1,2,4] is similar with 66% and [4,3,2,1] with [4,2,2,0] is similar to 50%. The return value should be the absolut number of similar entries (so for both examples it would be 2)

The simple approach would be to iterate through array 1 and compare with array 2 and increment a counter, if array1[i] == array2[I] but I guess this is not efficient.

thx. alex


User 2646 | 3/22/2016, 2:45:18 AM

Hi Alexander,

You can do something like this:

a = gl.SArray([1,2,3])
b = gl.SArray([1,2,4])
c = (a==b).mean()