Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • Thanks, this ran very fast! Does this method preserve order (not required for the purposes of my question, just wondering)? Commented Sep 6, 2018 at 0:35
  • @curious_cosmo a set is an unordered collection, so it does not preserve order. You could check out collections.OrderedDict (putting tuples as the keys) or this implementation of OrderedSet if you're interested in preserving order. Commented Sep 6, 2018 at 0:56
  • @Alexander the example you've just pointed out (set(np.matrix([1,2,1,2]))) is quite different from the solution I have posted. Yours converts the matrix [1 2 1 2] into a set {1, 2}, while mine converts a comprehension of tuples into a set. So yours is one level beneath what I have described in my answer. A more appropriate example would be set([np.matrix([1,2,1,2]), np.matrix([1,2,1,3])]), which produces {(1,2,1,2), (1,2,1,3)}, which is actually in line with the question. Commented Sep 6, 2018 at 1:06
  • You are correct. Sorry for the confusion and thanks for the detailed explanation. Commented Sep 6, 2018 at 1:08