Hi Ryan,Thank you very much indeed, I'm not sure if I well understood your code, let say, for the example array matrix given represents H3C-CH3 connection(bonding).
the result from your code is:
Rows: [0 0 0 0 1 1 1] # is these for C indices?
Columns: [1 2 3 4 5 6 7] # is these for H indices? but it shouldn't be 6 H's?
Atomic Distances: [ 1. 1. 1. 1. 1. 1. 1.] # ofcourse this is the number of connections or bonds.
In fact, if I write in the form of dictionary: row indices as keys and column indices as values,
{0:1, 0:2, 0:3, 0:4, 1:5, 1:6, 1:7}, So, does it mean C[0] is connected to H[1], C[0] is connected to H[2] , H[1],....,C[1] is connected to H[7]? But I have only 6 H's and two C's in this example (H3C-CH3)
I have tried some thing like: but still no luck ;(
import numpy as np
from collections import defaultdict
dict = defaultdict(list)
x=....2d numpy array
I = x.shape[0]
J = x.shape[1]
d={}
for i in xrange(0, I, 1):
for j in xrange(0, J, 1):
if x[i,j] > 0:
dict[i].append(j)
# the result is:
dict: {0: [1, 2, 3, 4], 1: [0, 5, 6, 7], 2: [0], 3: [0], 4: [0], 5: [1], 6: [1], 7: [1]})
keys: [0, 1, 2, 3, 4, 5, 6, 7]
values: [[1, 2, 3, 4], [0, 5, 6, 7], [0], [0], [0], [1], [1], [1]]
#The H indices can be found by
H_rows = np.nonzero(x.sum(axis=1)== 1)
result=>H_rows : [2, 3, 4, 5, 6, 7] # six H's
I am trying to connect this indices with the dict result but I am confused!
So, now I want to produce a dictionary or what ever to produce results as: H[2] is connected to C[?]
H[3] is connected to C[?]
H[4] is connected to C[?], .....
Thanks for any help
.