Moved xoring of arrays into function for profiling.  Reduced overhead of calculate_d() by initting zero array via numpy instead of list comprehension