Question: I have a strange situation here. I have that table structure

[![enter image description here](https://i.stack.imgur.com/Vv50a.png)](https://i.stack.imgur.com/Vv50a.png)

Whenever Cost is 0 I need to put Line 2 description together with Line 1 description.

I should get this at the end

[![enter image description here](https://i.stack.imgur.com/rgYD5.png)](https://i.stack.imgur.com/rgYD5.png)

I am trying to do this in c# but failing miserably.

So far, this is where I am at

[![enter image description here](https://i.stack.imgur.com/ZDcd7.png)](https://i.stack.imgur.com/ZDcd7.png)

Answer: 
You could do something like

```
d = 2*numpy.atleast_2d(a).T/(a+M)

```
With a pair of sample arrays (you should have provided these):

```
In [196]: a = np.arange(1,4); M = np.arange(1,10).reshape(3,3)                                                       
In [197]: a                                                                                                          
Out[197]: array([1, 2, 3])
In [198]: M                                                                                                          
Out[198]: 
array([[1, 2, 3],
       [4, 5, 6],
       [7, 8, 9]])
In [199]: d = 2 * M/(a[:,None]+a[None,:])                                                                            
In [200]: d                                                                                                          
Out[200]: 
array([[1.        , 1.33333333, 1.5       ],
       [2.66666667, 2.5       , 2.4       ],
       [3.5       , 3.2       , 3.        ]])

```

The `a[None,:]` could be simplified to `a`, but I wanted to clarify the broadcasting use to calculate this outer product. There are various tools in numpy for do this. I like the `None` indexing because it is simple and idiomatic.

testing against your code (again, you should have provided such a result):

```
In [202]: def foo(a): 
     ...:     d = np.zeros((3,3)) 
     ...:     for i in range(len(a)): 
     ...:         x = a[i] 
     ...:         for j in range(len(a)): 
     ...:             y = a[j] 
     ...:             z = M[i][j] 
     ...:             d[i][j] = 2 * z/(y+x) 
     ...:     return d 
     ...:                                                                                                            
In [203]: foo(a)                                                                                                     
Out[203]: 
array([[1.        , 1.33333333, 1.5       ],
       [2.66666667, 2.5       , 2.4       ],
       [3.5       , 3.2       , 3.        ]])

```