1

I got the following code:

line_gdf = Crewe.iloc[0:2500]
ma = line_gdf.geometry.apply(lambda g: line_gdf.intersects(g))   
lll = ma < 1  # Where values are low
ma[lll] = 0.0001  # All low values set to x
ma2 = ma
ma2  

0   1   2   3   4   5   6   7   8   9   ...     2340    2341    2342    2343    2344    2345    2346    2347    2348    2349
0   1.0000  0.0001  0.0001  0.0001  1.0000  0.0001  1.0000  0.0001  0.0001  0.0001  ...     0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001
1   0.0001  1.0000  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  ...     0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001
2   0.0001  0.0001  1.0000  0.0001  0.0001  1.0000  0.0001  1.0000  0.0001  0.0001  ...     0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001
3   0.0001  0.0001  0.0001  1.0000  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  ...     0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001
4   1.0000  0.0001  0.0001  0.0001  1.0000  0.0001  1.0000  0.0001  0.0001  0.0001  ...     0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001
...     ...     ...     ...     ...     ...     ...     ...     ...     ...     ...     ...     ...     ...     ...     ...     ...     ...     ...     ...     ...     ...
2345    0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  ...     0.0001  0.0001  0.0001  0.0001  1.0000  1.0000  0.0001  0.0001  0.0001  0.0001
2346    0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  ...     0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  1.0000  1.0000  0.0001  0.0001
2347    0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  ...     0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  1.0000  1.0000  1.0000  0.0001
2348    0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  ...     0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  1.0000  1.0000  0.0001
2349    0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  ...     0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  1.0000

2350 rows × 2350 columns

Now that gives me an indication which Edge intersects with which.

Now I want to take ma2 to the power of 3

    from numpy.linalg import matrix_power
    ma3 = matrix_power(ma2, 3) #instead of 3 we can take any number 
    ma3

array([[9.00266253e+00, 3.43913910e-03, 6.08561443e-03, ...,
        6.40905208e-03, 6.40905208e-03, 6.30907208e-03],
       [3.43913910e-03, 4.00041612e+00, 4.06251676e-03, ...,
        4.28597441e-03, 4.28597441e-03, 4.18599441e-03],
       [6.08561443e-03, 4.06251676e-03, 1.20033093e+01, ...,
        7.33236974e-03, 7.33236974e-03, 7.23238974e-03],
       ...,
       [6.40905208e-03, 4.28597441e-03, 7.33236974e-03, ...,
        1.90021563e+01, 1.40036562e+01, 7.75578740e-03],
       [6.40905208e-03, 4.28597441e-03, 7.33236974e-03, ...,
        1.40036562e+01, 1.70027563e+01, 7.75578740e-03],
       [6.30907208e-03, 4.18599441e-03, 7.23238974e-03, ...,
        7.75578740e-03, 7.75578740e-03, 1.90019564e+01]])

That returns expected outcome but without Row/Column referencing to edges.

I am not sure how to get the same shape of outcome as in step 1 when producing ma2

any hint ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.