# [Numpy-discussion] Any help from Numpy community?

Ryan rnelsonchem at gmail.com
Thu Mar 14 09:05:17 EDT 2013

```Birdada Simret <birdada85 <at> gmail.com> writes:

>
>
> Any help from Numpy community
> [[   0.          1.54        0.          0.          0.            1.08
1.08      1.08  ]
>
> [ 1.54        0.          1.08        1.08      1.08        0.          0.
0.   ]
>  [    0.       1.08         0.          0.           0.            0.
0.           0.   ]
>  [    0.       1.08         0.          0.           0.            0.
0.            0.    ]
>
>  [   0.        1.08        0.           0.           0.            0.
0.            0.    ]
>  [ 1.08       0.           0.           0.           0.            0.
0.            0.     ]
>
>  [ 1.08       0.           0.           0.           0.            0.
0.            0.     ]
>  [ 1.08       0.           0.           0.           0.            0.
0.            0.     ]]
>
>
> the above is the numpy array matrix. the numbers represents:
> C-C: 1.54 and C-H=1.08
> So I want to write this form as
> C of index i is connected to C of index j
> C of index i is connected to H of index j
>
>
> (C(i),C(j))  # key C(i) and value C(j)
> (C(i),H(j)) # key C(i) and value H(j) ; the key C(i) can be repeated to fulfil
as much as the values of H(j)
> To summarize,  the out put may look like:
>
> C1 is connected to C2
> C1 is connected to H1
> C1 is connected to H3
> C2 is connected to H2   etc....
>
> Any guide is greatly appreciated,
> thanks
> birda
>
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion <at> scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>

Birda,

I think this will get you some of the way there:

import numpy as np
x = ... # Here's your 2D atomic distance array
# Create an indexing array
index = np.arange( x.size ).reshape( x.shape )
# Find the non-zero indices
items = index[ x != 0 ]
# You only need the first half because your array is symmetric
items = items[ : items.size/2]
rows = items / x.shape
cols = items % x.shape
print 'Rows:   ', rows
print 'Columns:', cols
print 'Atomic Distances:', x[rows, cols]

Hope it helps.

Ryan

```