Skip to content

Instantly share code, notes, and snippets.

@sevas
Last active August 29, 2015 13:57
Show Gist options
  • Save sevas/9398125 to your computer and use it in GitHub Desktop.
Save sevas/9398125 to your computer and use it in GitHub Desktop.
import numpy as np
a = np.arange(0., 1.0, .1)
b = np.arange(0., 1.0, .1)
# modify 3 values to have differences
b[5:8] *= 1.1
indices_different = np.where(a != b)
# reason for indices_different[0] is because numpy is intrisically an n-dim
# linalg library so there is no such thing as 1-d arrays, and np.where returns
# a tuple of results, one entry per dimension in your input data.
# Sucks a bit for 1-d arrays.
print("found {} different values between a and b. Indices: {}".format(len(indices_different[0]), indices_different[0]))
print("diff values in a {}".format(np.take(a, indices_different)))
print("diff values in b {}".format(np.take(b, indices_different)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment