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:

  1. a , b 2 clusterings of same data.
  2. a , b have same number of clusters , b same length.
  3. 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

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -