求矩陣中向量兩兩間的歐氏距離(python實現)
假設有兩個三維向量集,用矩陣表示:
要求A,B兩個集合中的元素兩兩間歐氏距離。
先求出ABT:
然後對A和BT分別求其中每個向量的模平方,並擴充套件為2*3矩陣:
然後:
將上面這個矩陣一開平方,就得到了A,B向量集兩兩間的歐式距離了。
程式碼:
def EuclideanDistances(A, B):
BT = B.transpose()
# vecProd = A * BT
vecProd = np.dot(A,BT)
# print(vecProd)
SqA = A**2
# print(SqA)
sumSqA = np.matrix(np.sum(SqA, axis=1))
sumSqAEx = np.tile(sumSqA.transpose(), (1, vecProd.shape[1]))
# print(sumSqAEx)
SqB = B**2
sumSqB = np.sum(SqB, axis=1)
sumSqBEx = np.tile(sumSqB, (vecProd.shape[0], 1))
SqED = sumSqBEx + sumSqAEx - 2*vecProd
SqED[SqED<0]=0.0
ED = np.sqrt(SqED)
return ED
例子:
import numpy as np
import scipy as sp
# 向量矩陣
nodematrix = np.mat([[0.18454707,0.07877431,0.03511417,-0.32287475,0.23515885,-0.18110873,0.048741672,0.06893173,-0.23685655,0.043925785,0.31994045,-0.24165289,0.13900638,0.056432284,0.11355302,-0.04609316,-0.052616715,0.23289913,0.16946493,0.32099992,0.1409426,0.14139928,0.062529296,0.005625876,-0.024155464,0.09008224,-0.19214138,0.1398599,-0.069819,-0.14604269,0.3511576,-0.15226561,-0.14551574,-0.10126025,0.05427547,-0.24835448,0.15672702,-0.011962634,0.08181411,-0.06230553,-0.13467935,-0.009406202,-0.26009077,-0.1196819,0.31967723,-0.1310049,-0.18763539,0.11704104,-0.20122299,0.15155968,-0.1440493,-0.15665102,0.04375443,-0.24735771,0.0982016,0.101773486,0.1453648,-0.1844227,-0.08450979,-0.22261475,-0.078076385,0.07616588,0.053922217,0.071635224],
[0.16241522,0.030028613,0.00501509,-0.40497243,0.35783088,-0.1463465,0.1162642,0.0025282209,-0.19606775,0.08517304,0.2558237,-0.14098686,-0.059887953,0.18139145,0.16566025,-0.14257768,-0.03772987,0.1619154,0.15329891,0.30993557,0.24604511,0.13277014,0.045256298,-0.024693,-0.10674798,0.058585282,-0.29165882,0.24461408,0.005139245,-0.16787156,0.30382633,-0.14275697,0.06372774,-0.23374648,-0.048392028,-0.36086082,0.13913788,-0.16261087,0.043675978,-0.101465054,-0.117435366,-0.085971706,-0.36121935,-0.1571226,0.15281583,-0.0034408702,-0.08296094,0.3360551,-0.18179558,-0.057699423,-0.16708843,0.02841481,-0.06829184,-0.16543542,0.019792272,-0.0121178785,0.16203862,-0.22075787,-0.27897227,-0.24739979,-0.0762489,0.12593369,0.065210156,0.14470446],
[0.15471825,-0.009560898,0.044638064,-0.3334582,0.2528265,-0.023827955,0.2105105,-0.040138807,-0.12214413,0.13366897,0.20146476,-0.029900132,-0.033629015,0.10772486,0.073309004,-0.18203571,-0.03172069,0.049771123,0.09460871,0.08535822,0.17931731,0.08702089,0.07659155,-0.07248056,-0.15958676,0.05345656,-0.24768034,0.18058199,-0.06615136,-0.24867545,0.14499323,-0.14823414,0.10333892,-0.2746339,-0.015144608,-0.30523992,0.099423714,-0.16731471,0.13232969,-0.056383006,-0.1103352,-0.13529888,-0.2588229,-0.11967849,0.111871056,0.08303513,-0.092684194,0.25987405,-0.10226027,-0.14604586,-0.11458803,-0.04001497,-0.009192579,-0.02120677,0.14012279,-0.061846178,0.074880384,-0.25790447,-0.21985511,-0.30482677,-0.01992341,0.08783396,0.046929568,0.20357957],
[0.14336285,0.025450729,0.030937783,-0.38646004,0.3831792,-0.12658559,0.11587829,-0.00094238063,-0.20711565,0.116168045,0.2619768,-0.16534837,-0.076349474,0.1910923,0.1761144,-0.117769174,-0.05778647,0.15578617,0.1770518,0.3299434,0.28326258,0.11662979,0.030391019,-0.024187434,-0.13119648,0.11671877,-0.29864267,0.2607055,-0.0014046635,-0.16056718,0.32242507,-0.15809427,0.07620385,-0.24686214,-0.053542577,-0.3769508,0.15533,-0.18925558,0.03750794,-0.10124978,-0.12879665,-0.06370331,-0.39504737,-0.18121615,0.13492465,-0.013443653,-0.08084006,0.36568502,-0.20093451,-0.041457146,-0.20096765,0.05318851,-0.076807216,-0.18296471,0.021850985,0.0072131567,0.17274004,-0.24819276,-0.31100342,-0.2147306,-0.08602295,0.1464944,0.059046265,0.11183362],
[0.26588073,0.14150523,-0.066580854,-0.32842296,0.20054933,-0.311242,0.027391246,0.220159,-0.3213798,-0.059942015,0.43377757,-0.4325063,0.3782408,-0.057497203,0.14789854,-0.046590663,-0.013819736,0.44173974,0.20694812,0.45672962,0.12681784,0.15629336,0.10186779,-0.01538804,0.14938115,0.00080065127,-0.21110442,0.0750086,-0.08364635,-0.21890001,0.48687533,-0.18377657,-0.35746732,0.00683676,0.21058857,-0.1659275,0.10746653,0.20458831,0.10176073,-0.08301095,-0.18864691,0.07533139,-0.25550327,-0.057406623,0.5441203,-0.29227442,-0.32799053,-0.018170757,-0.25572824,0.27149796,-0.09855748,-0.38477862,0.18221247,-0.38255888,0.1667156,0.22324125,0.20890681,-0.12635048,0.098535806,-0.32271296,-0.10179064,0.029363632,0.09413725,0.0853047],
[0.28390682,0.14821959,-0.07243146,-0.31380302,0.17729533,-0.3514834,0.015846489,0.25777772,-0.35790017,-0.07803212,0.49184337,-0.466249,0.45263693,-0.09243493,0.14506024,-0.03347256,-0.059323907,0.4768754,0.23787509,0.51546514,0.08862736,0.1546034,0.1132154,-0.015038503,0.1742082,0.023245092,-0.18185928,0.06533995,-0.109746985,-0.23858051,0.5158076,-0.21007662,-0.4443825,0.05093318,0.23896919,-0.15287971,0.11856414,0.24033959,0.11668239,-0.0883758,-0.21929263,0.08000682,-0.25499132,-0.010891287,0.6080768,-0.34543636,-0.35245344,-0.094734706,-0.26169282,0.35251272,-0.09735272,-0.41804987,0.20288697,-0.4721476,0.19991674,0.28229624,0.22733806,-0.14755258,0.16689868,-0.34101963,-0.10447109,0.016718479,0.09580001,0.026380999],
[0.30237454,0.14683928,-0.038298786,-0.29058316,0.09569749,-0.2887462,0.08512673,0.25653952,-0.3306917,-0.07338041,0.43983808,-0.39612237,0.4771336,-0.15741485,0.08673556,-0.06200445,-0.05399839,0.43036908,0.19016203,0.36112237,0.037544876,0.16374564,0.13751066,-0.031518582,0.17014316,0.0054007443,-0.1412699,0.030166686,-0.1515889,-0.2804208,0.41181204,-0.20286052,-0.42974722,0.033308703,0.26093522,-0.101090506,0.11384971,0.25500837,0.16215882,-0.07417901,-0.20966761,0.038042348,-0.16307639,0.018035095,0.5900221,-0.3077835,-0.3638132,-0.16962387,-0.1844693,0.3052745,-0.060528554,-0.48142967,0.267378,-0.38124034,0.2627384,0.26814613,0.13943395,-0.13735828,0.2260544,-0.39549655,-0.08738619,-0.027837485,0.07852614,0.073204376],
[0.15111448,0.028105294,0.018643193,-0.39076355,0.35179225,-0.10192434,0.13584058,-0.01791851,-0.1876253,0.12551734,0.26209727,-0.14577623,-0.050282184,0.16817413,0.14472039,-0.12881413,-0.0009551516,0.14232564,0.14243901,0.24533655,0.26847097,0.11434139,0.043083258,-0.035031863,-0.12093203,0.07047154,-0.3023595,0.22925626,-0.022292228,-0.18379278,0.2770088,-0.14995696,0.07333245,-0.27771124,-0.027451774,-0.34053907,0.11851374,-0.16989794,0.06365318,-0.0777267,-0.120107174,-0.08308494,-0.34980863,-0.17573133,0.1607972,0.018753562,-0.11188955,0.34290648,-0.18527506,-0.06975901,-0.15833554,-0.0013007335,-0.05372122,-0.12500457,0.055650927,-0.038529787,0.1553037,-0.23561591,-0.29254356,-0.2623043,-0.064346865,0.13105302,0.06940119,0.16754109],
[0.1726481,-0.012440336,0.05777382,-0.29918647,0.11327566,0.028526327,0.25259495,-0.046879847,-0.083430484,0.14164263,0.18082081,0.035763584,0.06169322,-0.011473012,-0.028997375,-0.209982,-0.01166824,0.012950984,0.06836558,-0.08352182,0.07329331,0.08865248,0.12769547,-0.092709474,-0.13191105,0.0008182716,-0.17990653,0.113506615,-0.11055532,-0.31831446,0.03438223,-0.16406292,0.04131899,-0.2529639,0.03221567,-0.20100339,0.056884043,-0.06371642,0.21594793,-0.030609736,-0.113626,-0.18997502,-0.119332895,-0.060368035,0.17932867,0.09511753,-0.13219997,0.0711628,-0.035274208,-0.14551517,-0.029601278,-0.19388005,0.07590197,0.07678794,0.24299903,-0.084034674,-0.0004984068,-0.26196072,-0.07771122,-0.4030828,0.031955462,0.027905114,0.04942222,0.27295566],
[0.14423797,-0.0432808,0.08190974,-0.3191024,0.1842165,0.04050622,0.28313497,-0.099449195,-0.07827723,0.18302734,0.16223152,0.07542272,-0.048375804,0.05273844,0.011945316,-0.22902112,-0.02473319,-0.040633097,0.08694341,-0.06543084,0.14732157,0.08990496,0.11173066,-0.07845281,-0.22100301,0.045767106,-0.22423856,0.16899069,-0.07569042,-0.30694303,0.040872153,-0.16286385,0.14818484,-0.31789201,-0.043595877,-0.28272822,0.091681845,-0.18193623,0.1951894,-0.05589307,-0.107812,-0.22844492,-0.17869087,-0.11350503,0.08892242,0.15473714,-0.04950841,0.19699448,-0.04127596,-0.23042417,-0.07641474,-0.06739464,0.01028838,0.0937099,0.20463021,-0.13939577,0.0041027023,-0.30471212,-0.19514567,-0.38047338,0.03354903,0.083094895,0.05826267,0.2721687],
[0.2793651,0.15185933,-0.13177046,-0.33180004,0.17327645,-0.32736593,0.05041652,0.2559635,-0.33712912,-0.09623723,0.43651047,-0.4513071,0.43436667,-0.07025617,0.15559532,-0.069526486,0.014860244,0.50843346,0.1856622,0.4444423,0.1378033,0.15556376,0.1007079,-0.041156724,0.20312013,-0.071682364,-0.24855424,0.068367764,-0.07386292,-0.2374091,0.4783143,-0.19213393,-0.37353987,0.00675678,0.22759077,-0.12006049,0.031968668,0.26030996,0.10890474,-0.09292061,-0.18150233,0.067264214,-0.25004223,-0.025943859,0.5547775,-0.31370807,-0.37688726,-0.033713557,-0.23954678,0.24213813,-0.073403485,-0.4356436,0.20409836,-0.37392157,0.18340923,0.21839713,0.19377775,-0.07935003,0.121938154,-0.37857115,-0.09527563,-0.001988189,0.08951302,0.116948694],
[0.18911092,0.08160497,0.0016601636,-0.32320818,0.26116562,-0.2061808,0.05642223,0.09717212,-0.2437349,0.02547729,0.31445676,-0.26444656,0.13382575,0.06113216,0.15611434,-0.081660904,-0.036679324,0.27094358,0.17945346,0.3559872,0.17933144,0.1374297,0.07649111,-0.006217355,-0.005510128,0.058527853,-0.2241364,0.1594138,-0.05520337,-0.15667775,0.36725733,-0.1425781,-0.13560364,-0.11195341,0.061200168,-0.25109637,0.13808435,0.0022987318,0.058804743,-0.080964185,-0.14701879,-0.0037805818,-0.29680115,-0.122217305,0.3046953,-0.13382642,-0.1972336,0.16552013,-0.20034617,0.1101426,-0.149585,-0.14421572,0.05238,-0.25127417,0.09150396,0.11237208,0.15729831,-0.18274418,-0.094995774,-0.23815049,-0.10122151,0.07586146,0.068986915,0.082642585],
[0.16996923,0.049618036,0.05179584,-0.36588004,0.31677726,-0.13265298,0.106834866,-0.0020273838,-0.2127632,0.116691835,0.2884981,-0.14947754,-0.008221426,0.13122544,0.14508957,-0.11927571,-0.042859916,0.14708434,0.17431583,0.27867666,0.22840531,0.12445081,0.07174126,-0.002383612,-0.11935329,0.10622983,-0.2637777,0.21363659,-0.03331656,-0.17137319,0.299913,-0.14586169,0.01651397,-0.22818616,-0.01978779,-0.33883664,0.17199734,-0.13351218,0.062355887,-0.082700275,-0.13419996,-0.08728915,-0.32389545,-0.17075214,0.19168803,-0.019659597,-0.11455335,0.27489096,-0.18657012,-0.0026191298,-0.17362446,-0.030052122,-0.02440975,-0.16667756,0.073015906,0.014668574,0.14538196,-0.24565534,-0.22246717,-0.23394701,-0.08023288,0.12275762,0.056530964,0.11884437],
[0.1770716,0.036137342,0.025897793,-0.3234971,0.23756304,-0.09001872,0.16020681,0.00904371,-0.1735865,0.092177644,0.24534869,-0.112572536,0.021428583,0.07326688,0.1015288,-0.14751136,-0.014269934,0.12038724,0.14085414,0.16890608,0.1834341,0.11249428,0.08795087,-0.04018256,-0.08202991,0.030308079,-0.24744113,0.16103116,-0.042747904,-0.22646068,0.20006269,-0.14222224,0.01643619,-0.21936932,0.019911917,-0.25720072,0.11692248,-0.079053394,0.09235358,-0.076932766,-0.11392767,-0.09851545,-0.24589059,-0.11251388,0.19632381,-0.0059035756,-0.12298326,0.20045549,-0.13134803,-0.05491341,-0.10543296,-0.09079514,0.023404025,-0.09293511,0.11626331,-0.015003284,0.09801564,-0.2109043,-0.15492913,-0.301403,-0.04797976,0.07609193,0.060943007,0.17985934],
[0.20211908,-0.042457707,0.07963788,-0.24616125,-0.0016203935,0.08747425,0.3445378,-0.042892393,-0.029644443,0.15625161,0.14101058,0.13154906,0.09129875,-0.09838188,-0.09119842,-0.28851396,-0.0127152605,-0.05431411,0.031604573,-0.241091,0.004355231,0.07912117,0.16533026,-0.12881918,-0.13922673,-0.049737696,-0.134099,0.064189635,-0.14823043,-0.42220902,-0.08486823,-0.16549598,0.03138324,-0.2653847,0.07295038,-0.15953752,0.04588753,-0.029413931,0.27231637,-0.01733834,-0.11049157,-0.25405753,-0.013774244,0.007528906,0.17843299,0.14197133,-0.11709539,-0.022675624,0.05148694,-0.23617482,0.04841185,-0.2627152,0.15692478,0.1733869,0.33664265,-0.10141346,-0.07606096,-0.2797656,0.015396662,-0.49511054,0.077843055,-0.013165025,0.06397136,0.3398944],
[0.19333726,-0.06948673,0.06700214,-0.26560345,-0.0063666566,0.13355722,0.3935108,-0.09121974,0.0006445564,0.17690994,0.1210334,0.20084573,0.061550155,-0.08020058,-0.110446885,-0.32778805,0.02011841,-0.09637935,0.008434096,-0.32650867,-0.002338159,0.06358269,0.16888708,-0.14663433,-0.19053972,-0.0828333,-0.1571253,0.061955526,-0.1430994,-0.44535667,-0.15079567,-0.16597058,0.09977372,-0.30529138,0.042675372,-0.16377808,0.00083379616,-0.06057989,0.3228897,-0.01633302,-0.09876281,-0.30508602,-0.0016543436,-0.009775345,0.13695441,0.21431117,-0.10836423,0.014768737,0.07100882,-0.3270629,0.059775382,-0.2622903,0.14291492,0.2697926,0.36251116,-0.18341811,-0.106000684,-0.30717373,-0.013617679,-0.5441409,0.12265899,-0.009879035,0.06760865,0.40515727],
[0.3206641,0.16636348,-0.19939326,-0.32627803,0.108648,-0.37079093,0.052782707,0.334776,-0.36156029,-0.15277943,0.48536512,-0.52262056,0.59353334,-0.18255702,0.13896894,-0.06857194,0.028107084,0.6057365,0.19371368,0.45031837,0.075309165,0.13912944,0.12843287,-0.0695193,0.31171876,-0.13618183,-0.22805822,-0.003500298,-0.11347542,-0.31188983,0.52157295,-0.22881803,-0.49838233,0.0823455,0.33579263,-0.045575,-0.0116765825,0.39265206,0.16461997,-0.08262137,-0.21816555,0.10930331,-0.19812511,0.041591153,0.6959711,-0.38765556,-0.45808923,-0.1653151,-0.24739856,0.30601254,-0.020524703,-0.5982581,0.30081084,-0.42630625,0.2534135,0.2726562,0.21532036,-0.050672278,0.27728793,-0.45879433,-0.09230068,-0.04631962,0.12144143,0.1394169],
[0.18764953,0.074353084,0.014414537,-0.3664943,0.30646858,-0.1873455,0.0990077,0.05912998,-0.23949786,0.06814459,0.3100898,-0.21249554,0.06279928,0.106713496,0.16233696,-0.11900365,-0.047280524,0.21647662,0.18069345,0.32731667,0.21865857,0.13366474,0.068860814,-0.001435148,-0.06638469,0.06605377,-0.26006678,0.20950855,-0.039829172,-0.1787062,0.3249713,-0.151123,-0.057633173,-0.19424672,0.021133946,-0.29930088,0.1356837,-0.062951624,0.049746532,-0.10312361,-0.12884034,-0.054551557,-0.31612584,-0.13280685,0.25470656,-0.07790415,-0.14540653,0.22201511,-0.1809136,0.0503094,-0.14525011,-0.08016882,0.008718004,-0.2317869,0.075350694,0.05976003,0.1676282,-0.21528699,-0.16755617,-0.26486182,-0.091552444,0.0966181,0.07073366,0.09952136],
[0.20656243,-0.05493437,0.10121246,-0.27652383,0.04047083,0.10635354,0.34570587,-0.090846315,-0.03707599,0.18404184,0.15807,0.14529964,0.042038314,-0.045135748,-0.099228844,-0.27653813,-0.012136805,-0.08518722,0.037306774,-0.22383067,0.013750945,0.0932138,0.15258574,-0.1254065,-0.1985082,-0.017874172,-0.16256456,0.079131745,-0.14675297,-0.41209862,-0.06997334,-0.16171902,0.08405767,-0.28908318,0.035344575,-0.21616256,0.08199219,-0.0952345,0.28959334,-0.020985024,-0.120488934,-0.26009586,-0.043896083,-0.037450902,0.15811716,0.17166762,-0.116337,0.03571055,0.035060402,-0.23918669,0.0058311117,-0.22092204,0.12916629,0.18150884,0.33621666,-0.13332926,-0.08112064,-0.3040305,-0.04607629,-0.4795337,0.0806826,0.0063675186,0.060428448,0.34551728],
[0.15574507,0.031158496,0.025889365,-0.3166078,0.23441973,-0.08497615,0.13497964,0.010428588,-0.16753125,0.10656838,0.25335014,-0.11412931,0.045993775,0.064416245,0.09465493,-0.14728534,-0.02890273,0.12708062,0.13068125,0.16741318,0.17027277,0.098189905,0.091348775,-0.030892963,-0.08595323,0.041038554,-0.2208283,0.17574295,-0.054882217,-0.22253671,0.21895915,-0.15781753,-0.0038391924,-0.21290308,0.015343607,-0.25403592,0.09254359,-0.08448839,0.11902712,-0.072862044,-0.12523727,-0.10816764,-0.24557817,-0.11461377,0.20242864,-0.0041195783,-0.11990423,0.18795893,-0.1394945,-0.033840805,-0.10709163,-0.10437996,0.011707809,-0.0989231,0.12340804,-0.0077186255,0.109975256,-0.23920205,-0.15691365,-0.28742135,-0.033486035,0.078771405,0.07009493,0.15183546],
[0.18388785,-0.058792084,0.027780082,-0.29094037,0.05340126,0.088585675,0.3375004,-0.07134073,-0.026494885,0.15337496,0.14546503,0.12871636,0.052799303,-0.04440844,-0.06300934,-0.28551638,0.027462171,-0.036060985,0.018461896,-0.20726109,0.0462854,0.077469125,0.13859698,-0.13014948,-0.15488273,-0.08370285,-0.19345206,0.09172407,-0.1160029,-0.39699474,-0.047844876,-0.15594713,0.100354396,-0.2846791,0.029622942,-0.19003823,-0.0046438347,-0.059392687,0.2825639,-0.02534854,-0.102856055,-0.24490362,-0.05930478,-0.0129462965,0.13272402,0.1736737,-0.117019296,0.07523492,0.017747387,-0.29442048,0.023727618,-0.2221815,0.11057892,0.19946247,0.3068098,-0.16076404,-0.04762217,-0.26166674,-0.056535587,-0.49956068,0.085633874,0.019636396,0.067468114,0.3730747],
[0.16353792,0.059969667,0.021624805,-0.33980545,0.2802551,-0.16615838,0.09108739,0.03730565,-0.22399193,0.07656824,0.31536645,-0.20186754,0.06170617,0.08710088,0.14669493,-0.10211103,-0.05683562,0.1852904,0.17152719,0.3088051,0.19206654,0.11864391,0.07567623,-0.0074515366,-0.08527383,0.080874495,-0.23294587,0.19866833,-0.04184279,-0.16874757,0.31613696,-0.15008095,-0.058682553,-0.18297836,0.016088957,-0.28184915,0.14272103,-0.08436974,0.07878053,-0.08228577,-0.13777205,-0.058080193,-0.29017472,-0.13005894,0.24780533,-0.07675442,-0.13326707,0.18966763,-0.17597432,0.065882325,-0.15127045,-0.0754603,-0.0019098063,-0.22170939,0.08054309,0.056657713,0.16068824,-0.22702312,-0.16240408,-0.24396397,-0.07614332,0.10145783,0.06261243,0.07030048],
[0.19282828,-0.047765415,0.13060726,-0.27065924,0.0316827,0.09582964,0.3397643,-0.09725138,-0.02366595,0.18760464,0.15611611,0.16709767,0.030919738,-0.046297424,-0.096221186,-0.2877134,-0.04387901,-0.1091746,0.04731442,-0.22318278,-0.0034671586,0.08394346,0.1675105,-0.09862931,-0.22378139,0.0052971095,-0.13513303,0.087674975,-0.15179461,-0.39402306,-0.092841916,-0.16741027,0.07898361,-0.29163802,0.028966859,-0.21977012,0.09506184,-0.106869236,0.27429628,-0.01542279,-0.100537844,-0.2726963,-0.042389497,-0.025178771,0.13824257,0.17181072,-0.084468246,0.017248461,0.05014076,-0.22414048,0.013670202,-0.18905342,0.11725921,0.17509836,0.32815906,-0.12170149,-0.08443088,-0.32623225,-0.04509031,-0.4568871,0.086123444,0.01348874,0.04846637,0.3127399],
[0.20672143,-0.026862461,0.27854323,-0.21922615,0.0019582368,0.104448214,0.3892945,-0.10943327,-0.058883004,0.23335713,0.15824479,0.23975971,0.020190382,-0.117545806,-0.113654174,-0.30820343,-0.1822901,-0.21166769,0.09331975,-0.25000215,-0.048817705,0.1115871,0.24064803,-0.059292093,-0.2998885,0.1351057,-0.012736165,0.115458935,-0.20095997,-0.41367555,-0.16915117,-0.15988185,0.038226977,-0.33181876,0.013993497,-0.23626654,0.22967613,-0.12373063,0.25747216,-0.047873996,-0.14037319,-0.33041266,0.027925963,0.010396586,0.101038136,0.20711927,-0.008148601,-0.05140468,0.14114635,-0.18118912,-0.0105361855,-0.14318009,0.14530468,0.14039229,0.3882038,-0.046394527,-0.13282771,-0.4360763,0.013710599,-0.43906084,0.05577095,-0.01856298,0.03657196,0.22379681],
[0.21694721,0.010456647,0.47611696,-0.15822072,-0.026537968,0.057216592,0.35475415,-0.076435134,-0.09499785,0.2565587,0.22427312,0.2030649,0.034655925,-0.14694332,-0.13292962,-0.23097886,-0.3361215,-0.27947286,0.17132683,-0.16510579,-0.14948711,0.13752505,0.27814162,0.018502636,-0.36554793,0.34076846,0.123190045,0.13124645,-0.27340412,-0.3837541,-0.15401089,-0.15584072,-0.08076527,-0.2837032,0.018435482,-0.26464847,0.43176875,-0.17014429,0.21691386,-0.04071946,-0.16166924,-0.3161194,0.06375292,0.0055755703,0.14969043,0.13472529,0.021309424,-0.19152266,0.17899828,0.03720734,-0.04582734,-0.11226478,0.16613838,-0.016955167,0.40899011,0.12237978,-0.14574872,-0.5336515,0.10574918,-0.32658663,-0.0072400398,-0.036545094,-0.0034880359,0.015943548],
[0.22586057,0.0079153525,0.51730084,-0.14527033,-0.028050495,0.09582456,0.38745946,-0.09125328,-0.11272023,0.29725653,0.22932218,0.24419576,0.030297233,-0.17330515,-0.16059618,-0.25346324,-0.3598846,-0.328004,0.17246896,-0.22349332,-0.15866774,0.14216825,0.3085378,0.007880787,-0.40814963,0.36362466,0.13551553,0.1311254,-0.31004655,-0.40390885,-0.19426821,-0.17162715,-0.076164804,-0.31842723,0.021290706,-0.27360463,0.45201948,-0.19400027,0.22520578,-0.05654508,-0.17958976,-0.3378811,0.07338144,0.023247564,0.12378461,0.16229613,0.02822576,-0.19486034,0.1898419,0.027866086,-0.054091465,-0.099813335,0.17788918,0.00021082308,0.45319682,0.1147714,-0.15905458,-0.58886933,0.09526324,-0.35723752,0.015395171,-0.037683837,0.010731109,0.010727144],
[0.18624817,-0.075265266,0.09165288,-0.2981571,0.051451083,0.13485743,0.35846135,-0.11017401,-0.025422556,0.20520361,0.14135852,0.19727194,0.02197298,-0.041885763,-0.09224585,-0.3141351,-0.0093204975,-0.11044508,0.012086616,-0.26374882,0.04374105,0.0825035,0.15773496,-0.1343487,-0.20369309,-0.037485756,-0.15650488,0.097752385,-0.1298726,-0.42036688,-0.10957569,-0.15665986,0.11854316,-0.3358379,0.02179026,-0.2155553,0.029910158,-0.1013213,0.28967717,-0.02058653,-0.11267323,-0.28587437,-0.048559684,-0.030902773,0.12475562,0.2180536,-0.09432568,0.08612738,0.039317347,-0.31443208,0.022556474,-0.20505813,0.10249616,0.24212562,0.32630068,-0.18435018,-0.06906589,-0.30887273,-0.09196814,-0.4964829,0.09316997,0.027567847,0.065348364,0.37987813],
[0.18346646,0.0025293792,0.31624827,-0.20245348,0.066979356,0.042108882,0.3193282,-0.062068377,-0.11341074,0.223898,0.22361392,0.1381856,0.008999847,-0.082655616,-0.063638024,-0.2112711,-0.2120614,-0.18006031,0.13397938,-0.1091848,-0.0332879,0.13050975,0.20824264,-0.013214301,-0.28531477,0.22152719,0.0020361538,0.13706447,-0.2026345,-0.3265868,-0.061965436,-0.15259081,-0.015868995,-0.29475147,-0.00068454584,-0.25657684,0.3016746,-0.15756942,0.17686233,-0.056815147,-0.1391062,-0.26579094,-0.026387265,-0.019134186,0.120411664,0.12932403,-0.020332975,-0.033654194,0.08203207,-0.04271986,-0.057319146,-0.0811756,0.11496089,-0.008523536,0.3130296,0.041794546,-0.06338264,-0.43767628,-0.0030200134,-0.33798292,0.010774982,0.019431382,0.022383675,0.08704545],
[0.17571062,-0.011469975,0.15649606,-0.2643043,0.12717274,0.02692581,0.25380075,-0.043617368,-0.10675683,0.16915043,0.16941032,0.05337308,0.006199969,-0.0018220326,-0.01664542,-0.22198068,-0.10723307,-0.04996807,0.10724021,-0.04331694,0.07575021,0.081761606,0.1475314,-0.07214804,-0.18618259,0.10170803,-0.12177372,0.14445244,-0.1261494,-0.3130462,0.013943998,-0.16070871,0.044943724,-0.26207134,0.012609351,-0.23878312,0.163888,-0.13003813,0.16799435,-0.060234133,-0.13124394,-0.20501982,-0.121592306,-0.06203265,0.13169782,0.09891591,-0.051692605,0.085582145,0.0029683202,-0.107652,-0.064190194,-0.10658767,0.059180308,0.024863642,0.23873647,-0.04186117,-0.010660089,-0.31883386,-0.0911426,-0.34818494,0.0010433042,0.038582787,0.04468579,0.18897213],
[0.19978541,-0.06269709,0.18639617,-0.25699544,-0.0021046952,0.13748443,0.38772556,-0.120610744,-0.013478544,0.23707856,0.15709771,0.25102696,0.017202059,-0.097636305,-0.14126106,-0.33171287,-0.082857825,-0.19492286,0.04694955,-0.30608943,-0.038510036,0.080974475,0.20771983,-0.09557598,-0.28731287,0.04976665,-0.09070368,0.10414424,-0.19000207,-0.44676188,-0.16060731,-0.17408675,0.084936365,-0.33386317,0.0132134,-0.23127742,0.11897614,-0.13159347,0.32275584,-0.017176488,-0.13519044,-0.33501804,-0.00010217828,-0.023053672,0.1303666,0.22151065,-0.05315132,-0.0048879897,0.09662842,-0.27033716,0.006487973,-0.19641487,0.1242154,0.22838081,0.3907593,-0.14592206,-0.12365343,-0.3972139,-0.026467655,-0.50687057,0.11091795,0.017713785,0.050476927,0.32557613],
[0.15848581,-0.021518586,0.055416178,-0.29590598,0.14921555,0.027564738,0.27866402,-0.06480973,-0.06561603,0.1425454,0.16373344,0.06395436,0.004325077,0.036353577,0.005580972,-0.23743598,-0.010105353,-0.0054508736,0.066414915,-0.07238929,0.107723005,0.083478,0.10714062,-0.08020742,-0.17946988,0.0050296765,-0.21389897,0.13545002,-0.08538656,-0.31768647,0.029560193,-0.14967662,0.10770875,-0.28728426,-0.0042626928,-0.24491496,0.059569046,-0.12545338,0.2075735,-0.045665283,-0.089441404,-0.2136854,-0.15041624,-0.07455663,0.116795145,0.12470212,-0.09009074,0.15079838,-0.02099774,-0.21263364,-0.041026678,-0.12918334,0.04661082,0.08647262,0.21170008,-0.11597091,-0.009324394,-0.27021712,-0.13773955,-0.39590207,0.031859852,0.052892074,0.05693203,0.26746127],
[0.22189528,0.030154562,0.32983,-0.17216372,0.010209753,0.013682198,0.30596247,-0.020119933,-0.116517276,0.18875667,0.22976357,0.10180245,0.08720732,-0.13262396,-0.08771802,-0.2145837,-0.23811126,-0.14074588,0.14721522,-0.104157664,-0.08373347,0.12757854,0.22939226,-0.0132875815,-0.23682074,0.22550811,0.035497826,0.10365179,-0.22575136,-0.35665202,-0.069766305,-0.1563962,-0.087144546,-0.23151217,0.06410427,-0.21941258,0.31399256,-0.08988898,0.19147775,-0.05470761,-0.1572297,-0.23998182,0.0188208,0.012140833,0.18857075,0.07372459,-0.05697793,-0.14147809,0.106876954,0.030187905,-0.03988606,-0.17364228,0.1706905,-0.039083384,0.35739434,0.097701006,-0.09385791,-0.41464764,0.10418368,-0.33557174,-0.0045919474,-0.02763886,0.011202594,0.070499904],
[0.17531455,-0.044787217,-0.009131567,-0.2881231,0.059869025,0.07599193,0.327584,-0.074285924,-0.030104812,0.15455334,0.1343466,0.13907082,0.07308012,-0.05146641,-0.04598773,-0.31512836,0.047161717,-0.004205145,0.01566227,-0.2205183,0.0812648,0.047852006,0.16366541,-0.12835477,-0.13141574,-0.0953081,-0.19711849,0.096778326,-0.09162709,-0.40242305,-0.06605699,-0.1719241,0.11284866,-0.3027889,0.03486293,-0.16696817,-0.05857623,-0.03665113,0.25314066,-0.031925574,-0.09856528,-0.25740013,-0.090104274,-0.014143765,0.12359994,0.18224698,-0.11498212,0.10484158,0.018188905,-0.32359672,0.040288206,-0.22474088,0.08212929,0.2039104,0.29720163,-0.18186975,-0.024886832,-0.2779924,-0.059329055,-0.5010534,0.09697687,0.008722061,0.086008765,0.37539345],
[0.17685892,-0.049328245,0.069831386,-0.30092248,0.090350956,0.10929393,0.33366963,-0.09147194,-0.047566082,0.1854566,0.15903713,0.12734325,0.04860585,-0.031574704,-0.07594497,-0.26819673,-0.0031301803,-0.052297626,0.024744488,-0.21933036,0.06396181,0.07063064,0.14660215,-0.12421251,-0.20001669,-0.0018085735,-0.17249289,0.1152019,-0.14527637,-0.37708488,-0.053285465,-0.177324,0.09767333,-0.32052764,0.026820146,-0.22028546,0.024559041,-0.11973184,0.28401002,-0.0048154476,-0.116903506,-0.25389233,-0.08461089,-0.06103407,0.13181527,0.18670411,-0.121669315,0.083243914,0.0050915745,-0.25549623,-0.0007974085,-0.21008848,0.07717522,0.17593127,0.31061208,-0.15265298,-0.051967423,-0.31836212,-0.08692709,-0.46341407,0.0834318,0.033166405,0.058264393,0.32750255]])
#%%
def EuclideanDistances(A, B):
BT = B.transpose()
vecProd = np.dot(A,BT)
SqA = A**2
sumSqA = np.matrix(np.sum(SqA, axis=1))
sumSqAEx = np.tile(sumSqA.transpose(), (1, vecProd.shape[1]))
SqB = B**2
sumSqB = np.sum(SqB, axis=1)
sumSqBEx = np.tile(sumSqB, (vecProd.shape[0], 1))
SqED = sumSqBEx + sumSqAEx - 2*vecProd
SqED[SqED<0]=0.0
ED = np.sqrt(SqED)
return ED
Euclidean_dis=EuclideanDistances(np.array(nodematrix),np.array(nodematrix))
print (Euclidean_dis)
執行結果:
相關文章
- 馬氏距離與歐氏距離
- 機器學習中的矩陣向量求導(五) 矩陣對矩陣的求導機器學習矩陣求導
- 計算地圖中兩點之間的距離地圖
- 機器學習中的矩陣向量求導(四) 矩陣向量求導鏈式法則機器學習矩陣求導
- 馬氏距離
- JAVA計算兩經緯度間的距離Java
- python兩個三階矩陣相乘Python矩陣
- 最小距離分類器,互動式選取影像樣本分類資料,進行最小距離分類(實現歐式距離,馬氏距離,計程距離)
- 28、(向量)歐幾里得距離計算
- 實現一個函式,對給定平面任意兩點座標(x 1 ,y 1 )和(x 2 ,y 2 ),求這兩點之間的距離函式
- 通過sql 計算兩經緯度之間的距離SQL
- C語言:使用函式計算兩點間的距離C語言函式
- python實現給定一個數和陣列,求陣列中兩數之和為給定的數Python陣列
- 向量和矩陣求導公式總結矩陣求導公式
- milvus 使用 l2 歐式距離計算向量的距離,計算出來的距離的最大值是多少?
- 根據經緯度計算兩點之間的距離的公式公式
- 根據兩點經緯度計算距離和角度——java實現Java
- C++語言演算法之求任意兩個相同字元的最大距離C++演算法字元
- 向量化實現矩陣運算最佳化(一)矩陣
- Java中實現並行請求兩種方式Java並行
- 三維空間中物體兩次旋轉之間的連續旋轉矩陣計算矩陣
- 求任意矩陣的伴隨矩陣矩陣
- 求陣列中是否存在滿足特定和的兩個數字(python & Js)陣列PythonJS
- matlab比較兩個矩陣是否相等Matlab矩陣
- torch中向量、矩陣乘法大總結矩陣
- 用一個巨集實現求兩個數中的最大數
- css實現兩欄固定中間自適應CSS
- 基向量 變換矩陣矩陣
- numpy.linalg包函式用法集錦(求逆矩陣,求矩陣行列式的值,求特徵值和特徵向量,解方程組)函式矩陣特徵
- 矩陣的特徵值和特徵向量矩陣特徵
- 【Python】距離Python
- 矩陣求導矩陣求導
- 矩陣求逆矩陣
- python 程式池的兩種不同實現Python
- leetcode-624.陣列列表中的最大距離LeetCode陣列
- [Python手撕]兩個升序陣列的中位數Python陣列
- 【Leetcode 每日一題】1030. 距離順序排列矩陣單元格(水題,曼哈頓距離排序)LeetCode每日一題矩陣排序
- Python+numpy實現矩陣的行列擴充套件Python矩陣套件