python - Pythonic way to check if two list of list of arrays are equal -
i have 2 lists of lists of numpy arrays called , b , want check each list inside a, there exists list in b same (contains same arrays).
here's example.
= [[np.array([5,2]), np.array([6,7,8])], [np.array([1,2,3])]]
b = [[np.array([1,2,3])], [np.array([6,7,8]), np.array([5,2])]]
basically, wondering if there pythonic/elegant way write function f(a, b) == true.
why should true?
a[0] = [np.array([5,2]), np.array([6,7,8])]. there matching list in b.
b[1] = [np.array([6,7,8]), np.array([5,2])]
a[0] , b[1] both contain same set of vectors: np.array([6,7,8]), np.array([5,2]).
a[1] = [np.array([1,2,3])]. there matching list in b.
b[0] = [np.array([1,2,3])].
therefor, return true.
some context:
- a , b 2 clusterings of same data.
- a , b have same number of clusters , b same length.
- a[0] list of arrays representing vectors belong 0th cluster in clustering.
basically, want check whether , b clustered data same clusters. i'm not sure whether can compare a[i] , b[i].
try use numpy.array_equal, can use code this:
>>> import numpy np >>> np.array_equal(np.array([[1,2],[2,1]]), np.array([[1,2],[2,1]])) true
Comments
Post a Comment