Skip to content
Advertisement

Getting all row indices in numpy 2d array where elements in each row exists more than 2 times in entire array

I am working with graph data defined as 2d array of edges. I.e.

JavaScript

Defines a graph, all elements define a node id, there are no self loops, it is directed, and no value in a column exists in the other column.

Now to the question, I need to select all edges where both ‘nodes’ occur more than once in the list. How do I do that in a quick way. Currently I am iterating over each edge and looking at the nodes individually. It feels like a really bad way to do this.

Current dumb/slow solution

JavaScript

I am also not entirely sure this way is even correct…

Advertisement

Answer

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement