Skip to content
Snippets Groups Projects
Commit 2f64e6de authored by Dennis Noll's avatar Dennis Noll
Browse files

[tools] numpy: adds intersect2d

parent 283c73f2
No related branches found
No related tags found
No related merge requests found
......@@ -75,3 +75,15 @@ def template_to(inp, template):
xsel(np.argsort(inp, axis=-1), 1, np.argsort(np.argsort(template, axis=-1), axis=-1), 1),
axis=-1,
)
def intersect2d(A, B, *args, **kwargs):
nrows, ncols = A.shape
dtype = {"names": ["f{}".format(i) for i in range(ncols)], "formats": ncols * [A.dtype]}
C = np.intersect1d(A.view(dtype), B.view(dtype), *args, **kwargs)
if len(C) > 0:
c = C[0]
else:
c = C
c = c.view(A.dtype).reshape(-1, ncols)
return C
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment