New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
n-array versions of set operations, especially intersect1d #5179
Comments
I can't think why we would have any objection to these in principle, though
|
Absolutely. Before I do that, do you have an opinion on the issues raised in the referenced email thread? I suppose for API stability n-matrix versions should be added as seperate functions, but should they be implemented by repeatedly calling the respective two-matrix versions, or is something like the provided implementation preferrable? |
API issues should be raised on numpy-discussion for the community to weigh I guess it's possible that there are people passing the assume_unique I don't really care about the implementation much myself, since I'm not the
|
Well, since the method, both old and new, is sorting based, when you intersect My point is that there probably is no major advantage to what you propose over something like |
Wow, I wasn't aware of reduce() until now, thanks for the hint! I agree this is a better solution. I'll submit a patch which adds an example of this instead. |
Built-in reduce annoyingly requires an identity, so I think it'd be reduce(np.intersect1d, arrays, [])
|
The third argument is the initializer, so adding [] results in the first intersect being between [] and array1 (if I've understood the API docs correctly), resulting in []. Not exactly what's intended :-) |
Doh, I was thinking of union obviously. Well, give it a try - it's possible reduce(intersect1d, arrs[1:], arrs[0]) but I'm on my phone so don't take my word for it (as if you would after my
|
reduce(np.intersect1d, arrays) as suggested by Jaime actually works perfectly for me. Thanks to both of you for the input! |
The approach was suggested by Jaime Frio in issue numpy#5179.
The stock Python set operations support multiple inputs, while the Numpy equivalents only support two arrays.
A version of intersect1d supporting n arrays was posted to numpy-discussion back in 2009: http://numpy-discussion.10968.n7.nabble.com/intersect1d-for-N-input-arrays-td25956.html
The posted multi-array version works well for me, it would be great to see it (or a variant) in Numpy.
The text was updated successfully, but these errors were encountered: