0

I am analyzing a network using networkx. The networkx is stored in pandas dataframe, to create the graph I use a set of data q stored in numpy array 5053x5053, then assign the serial numbers (taken from a file stored in numpy array serials) to index and columns :

Import networkx as nx
Import pandas as pd

network = pd.DataFrame (data = q, index = serials, columns = serials)

G = nx.from_numpy_matrix(network.values)

then i relabel the nodes:

G = nx.relabel_nodes(G, dict(enumerate(network.columns)))

I have a subgraph given by green products, and I have stored their serial numbers in another file imported like a numpy array (named greens). I need to have a new array to work on the two subgraph green and no green removing all the elements of green from serials.

Is there a function in numpy or should I use dicitonaries(how?)?

EDIT: Here's a sample. Serial is a numpy array with 5053 values:

[ 10110  10190  10210 ... 970500 970600 999999]

Greens is a numpy array with 255 values:

[840410 840510 841410 ... 903210 460120 843680]

I would like to have a new array with 5053-255 values removing from serial the elements of greens. Example: Import numpy as np

a = np.array([1,5,7,9,45,52,59])
b = np.array ([1,9,52])

The output I would like to get is

c = np.array([5,7,45,59])
1
  • Can you provide us with an example input and desired output? Commented Jul 16, 2020 at 16:37

1 Answer 1

2

Use np.setdiff1d - Return the unique values in a that are not in b.

a = np.array([1,5,7,9,45,52,59])
b = np.array ([1,9,52])

c = np.setdiff1d(a,b)
c
array([ 5,  7, 45, 59])

Sign up to request clarification or add additional context in comments.

1 Comment

And if order in the list matter, use [i for i in a if i not in b]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.