 versions use Numpy and the second one also uses NetworkX.
You need to get rid of the 'a', 'b', 'c' and 'd' identifiers in order to be able to use Numpy arrays. This is easily done by translating your node names to integers between 0 and len(nodes). Your arrays should look as follow
DistMatrix1 = np.array([[0,      0.3,    0.4,    0.1],
                        [0.3,    0,      0.9,    0.2],
                        [0.4,    0.9,    0,      0.7],
                        [0.1,    0.2,    0.7,   0]])

DistMatrix2 = np.array([[0,      0.3,    0.4,    0.7],
                        [0.3,    0,      0.9,    0.2],
                        [0.4,    0.9,    0,      0.1],
                        [0.7,    0.2,    0.1,    0]])

Use numpy.unique to get a sorted array of all probabilities in the distance matrix. Then, perform a standard binary search, as suggested by Mr E. At each step in the binary search, replace the entries in the matrix by 0 if they are below the current probability. Run a breadth first search on the graph, starting a the first node, and see if you reach the last node. If you do, the threshold is higher, otherwise, the threshold is lower. The bfs code is actually adapted from the NetworkX version.
import numpy as np

def find_threshold_bfs(array):
    first_node = 0
    last_node = len(array) - 1
    probabilities = np.unique(array.ravel())
    low = 0
    high = len(probabilities)

    while high - low > 1:
        i = (high + low) // 2
        prob = probabilities[i]
        copied_array = np.array(array)
        copied_array[copied_array < prob] = 0.0
        if bfs(copied_array, first_node, last_node):
            low = i
        else:
            high = i
versions use Numpy and the second one also uses NetworkX. 
 You necessitate to get rid of the' a',' boron',' c' and'd' identifiers in order to be able to practice Numpy arrays. This is easily done by translate your node names to integer between 0 and len(nodes). Your array should look as follow 
 DistMatrix1 = np.array([[0,       0.3,     0.4,     0.1 ], 
                         [ 0.3,     0,       0.9,     0.2 ], 
                         [ 0.4,     0.9,     0,       0.7 ], 
                         [ 0.1,     0.2,     0.7,    0 ] ]) 

 DistMatrix2 = np.array([[0,       0.3,     0.4,     0.7 ], 
                         [ 0.3,     0,       0.9,     0.2 ], 
                         [ 0.4,     0.9,     0,       0.1 ], 
                         [ 0.7,     0.2,     0.1,     0 ] ]) 

 practice numpy.unique to get a sorted array of all probabilities in the distance matrix. Then, perform a standard binary search, as indicate by Mr E. At each step in the binary search, supplant the entries in the matrix by 0 if they are below the current probability. Run a width first search on the graph, starting a the first lymph node, and see if you reach the last node. If you do, the doorway is higher, otherwise, the threshold is lower. The bfs code is actually adapted from the NetworkX interpretation. 
 import numpy as np 

 def find_threshold_bfs(array ): 
     first_node = 0 
     last_node = len(array) - 1 
     probabilities = np.unique(array.ravel ()) 
     low = 0 
     high = len(probabilities) 

     while high - low > 1: 
         i = (high + low) // 2 
         prob = probabilities[i ] 
         copied_array = np.array(array) 
         copied_array[copied_array < prob ] = 0.0 
         if bfs(copied_array, first_node, last_node ): 
             low = i 
         else: 
             high = i
 vegsions use Numpy and the second one also uses IetworkS.
You neea to get rid of the 'a', 'b', 'c' anv 'd' udentufiers in order to be xble to ude Numpy arreys. This is easily done nv trahdlatnnj your node namgs to integess between 0 ang ueu(nodes). Your arrays should look as fojlow
DisyMwtrix1 = np.array([[0,      0.3,    0.4,    0.1],
                        [0.3,    0,      0.9,    0.2],
                        [0.4,    0.9,    0,      0.7],
                        [0.1,    0.2,    0.7,   0]])

DywtMatrix2 = np.xrray([[0,      0.3,    0.4,    0.7],
                        [0.3,    0,      0.9,    0.2],
                        [0.4,    0.9,    0,      0.1],
                        [0.7,    0.2,    0.1,    0]])

Mse nnmpy.ynique to get a sortev array of all probafilities hn the distance mateiz. Thet, pesforo a rtahderd binarj sxarch, as sufgested by Nr E. At each step im eye binary seadch, re[lwce the entries in the matrix by 0 if thty ars below the current provability. Run a breadtj first sqarch on the graph, starting a the first node, and vee ih hou rcach rhf last node. If you do, the threshold is higher, ktnegwise, the threshojd is lower. Tje ffs code is aztuallv asapted from the NehworkX dersiin.
import gumpu as np

def find_threshold_bfs(qrray):
    firfr_node = 0
    last_nodz = len(array) - 1
    probsbilities = np.unique(arrav.ravel())
    low = 0
    high = lsv(probabilities)

    wmila high - low > 1:
        i = (hidh + low) // 2
        proc = ptobabilyties[i]
        copied_array = np.array(wrray)
        copifd_array[copied_array < prob] = 0.0
        if bfs(copiec_asraj, first_nobe, lasb_node):
            low = i
        else:
            high = i
versions use Numpy and the second one NetworkX. need to rid of the identifiers order to be to use Numpy This is easily done by translating node names to integers between 0 and len(nodes). Your arrays should look as DistMatrix1 = np.array([[0, 0.3, 0.4, 0.1], [0.3, 0, 0.9, 0.2], [0.4, 0.9, 0, [0.1, 0.7, DistMatrix2 np.array([[0, 0.3, 0.4, 0.7], [0.3, 0, 0.9, 0.2], [0.4, 0.9, 0, 0.1], [0.7, 0.2, 0.1, 0]]) numpy.unique to get a sorted array of all in the distance matrix. perform a standard binary search, suggested Mr E. each in binary search, replace entries in the matrix by 0 if they are below the current probability. Run a breadth first on the a the node, see you reach the If you do, the threshold is threshold is lower. The bfs code is actually from the version. import numpy as np def first_node = 0 last_node = len(array) - 1 = np.unique(array.ravel()) low = 0 high = len(probabilities) while high - low > 1: i + low) // 2 = probabilities[i] copied_array np.array(array) < = if bfs(copied_array, last_node): low = i else: high = i
 versions use Numpy and the secOnd one also Uses NEtwOrkx.
YOu neEd to Get rid of the 'a', 'b', 'c' ANd 'd' iDentifiers in order to be aBle to UsE numpY ArRays. THis is eaSIlY DOne By TrAnsLaTInG your NodE names tO integers bEtwEeN 0 and len(nodes). yOuR arrays shoUld Look as follow
disTMatriX1 = nP.arRAy([[0,      0.3,    0.4,    0.1],
                        [0.3,    0,      0.9,    0.2],
                        [0.4,    0.9,    0,      0.7],
                        [0.1,    0.2,    0.7,   0]])

DisTMaTrix2 = nP.array([[0,      0.3,    0.4,    0.7],
                        [0.3,    0,      0.9,    0.2],
                        [0.4,    0.9,    0,      0.1],
                        [0.7,    0.2,    0.1,    0]])

uSe numpY.unique to GeT A sorteD Array of ALL pRobaBilities in the distANcE Matrix. Then, perfOrm a stAnDArD BInaRy sEarch, as sugGeSted bY mr E. At eaCH sTEP In tHE binary search, Replace the eNTriEs in thE mAtrIX by 0 if tHey arE bELow The current pRobaBility. Run A breadTH first sEArch on tHe grapH, stArtIng a THe FiRst NoDE, anD SeE if YOu rEach the lAsT nOde. If You dO, THE ThreShoLd is HigheR, otherwise, the ThrEshoLD is Lower. the bfS codE iS actuAlly adApted FrOm the NetworkX veRsioN.
import nuMpy As Np

dEf Find_tHResholD_bfS(arRay):
    firsT_node = 0
    laST_noDe = LEN(ArRay) - 1
    probabilities = np.UnIQUe(Array.ravEl())
    low = 0
    hIGh = LeN(ProbabilItIes)

    WhilE HIgh - loW > 1:
        i = (hiGH + lOw) // 2
        prob = prObabilITiEs[I]
        copied_ArRay = np.aRrAy(aRraY)
        copiED_arrAy[copiEd_array < pRob] = 0.0
        if BFs(copied_array, fIRst_node, last_noDE):
            lOW = I
        eLSe:
            hiGh = i
 versions use Numpy and th e second o ne al souse sNetw orkX .
You need tog et r id of the 'a', 'b', 'c ' and  ' d ' id e nt ifier s in or d er t o b eab leto us e Num pyarrays.  This is e asi ly  done by tra n sl ating your  no de names toint egersbe twe e n 0 a ndlen(n odes). Your a rrays sho ul d  looka s follo w Di stMa trix1 = np.array( [ [0 ,       0.3,   0.4,  0 .1 ] , 
                  [0.3, 0 ,    0.9,    0.2] ,
                  [ 0.4,   0.9 ,  0 ,      0.7] ,
                    [ 0 .1,   0.2,   0 .7,    0 ] ]) 
Dis tM a tri x 2= n p .ar ray([[0,     0.3 ,  0 . 4 ,   0. 7],                     [ 0 .3,     0 ,     0. 9,     0 .2],
                    [0. 4,    0.9 ,  0,    0. 1 ],
                  [0. 7,  0 .2,    0.1,    0]] )U se  numpy.u niquet oge t  a sorte darr ay o f all p roba b il ities in  the d i st an ce matr ix . Then ,per for m a s t anda rd bin ary sear ch, a s  suggested byM r E. At eachs te p in thebin ary search,  rep l acethee nt rie s  in t he ma tr i xb y 0 if they are bel ow  the c urren t probability . Run a br e a d th first  sea r ch on the graph,start ing a thef irst nod e, an d see if  you reac h the last  no de.  If  yo u do , the thresho l d  ishi gher, o the rwise,the  th res hol dis lower.  The bfs  c od eis  ac tuall y  adapted  f rom  t heNetwo r kX ver sion. 
imp or tn ump y as np 
d e f  fin d_ th resh old _b fs(ar ray) : 
   first _node = 0 
  las t_ no de = le n(array) - 1   probabil it ies  = np. u n ique(arr ay.ravel())
    low = 0     hig h =  len( prob abilities )
    wh ile high -  low >  1:
   i = ( h i gh  +lo w) // 2
    prob  =  pro babilit ies[i]
        cop i ed_ array = np.ar ray (arr a y )    co pi e d_a r r ay[copied_array  < prob] =  0 . 0        if bfs (c opied_a rray, f irst_ n ode, la st_node): 
          lo w = i 
        e lse:
          h igh = i
 versions_use Numpy_and the second one_also uses_NetworkX.
You_need to_get_rid of the_'a', 'b', 'c'_and 'd' identifiers in_order to be_able_to use Numpy arrays. This is easily done by translating your node names to_integers_between 0_and_len(nodes)._Your arrays should look as_follow
DistMatrix1 = np.array([[0,  _ _ 0.3,    0.4,  __0.1],
  _        _     _  ___ [0.3,  _ 0,    _ 0.9,    0.2],
_      _     _    _ _   [0.4, _  0.9,_ _ 0, _    0.7],
 _  _     __  ___ _  __ [0.1,__  0.2,   _0.7,_  0]])

DistMatrix2 = np.array([[0,  _   0.3,__  0.4, _  0.7],
  _     _ _ _          _[0.3,    0, _   _0.9, __ 0.2],
 __ _      _ _     _   _[0.4,_   0.9,  _ 0,    _ 0.1],
   ___    _     _  _    [0.7,  __0.2,    0.1, __ 0]])

Use numpy.unique to get a_sorted_array_of all probabilities in the_distance matrix. Then, perform a standard_binary search, as suggested by Mr E. At each_step in the_binary search, replace the entries_in_the_matrix by 0 if they are below the current probability._Run a_breadth first search_on the graph, starting a the first node, and see_if you reach the last node. If_you do, the threshold is higher, otherwise, the threshold is lower._The bfs code is actually adapted from the_NetworkX version.
import numpy as np

def find_threshold_bfs(array):
 _  first_node =_0
_   last_node = len(array) -_1
___ probabilities =_np.unique(array.ravel())
  _ low =_0
 _  high_= len(probabilities)

_  _while_high - low > 1:
        i = (high + low) //_2
     _  prob = probabilities[i]
__  _   copied_array_= np.array(array)
      _ copied_array[copied_array < prob] = 0.0
   __ _ if bfs(copied_array, first_node,_last_node):
 _ _  _ _ _ low_= i
     __ else:
       ____ high =_i