日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python xyz_python中xyz坐标的欧几里德距离

發布時間:2023/12/20 python 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python xyz_python中xyz坐标的欧几里德距离 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

使用生成器表達式的簡單解決方案From PEP 289 Generator Expressions

Rationale

Experience with list comprehensions has shown their widespread utility

throughout Python. However, many of the use cases do not need to have a full list created in memory. Instead, they only need to iterate over the elements one at a time.

因為你不需要保存中間結果

可能你有一個大的數據集

以及itertools標準庫模塊中的^{},因為您需要計算數據集中每對有趣的點的距離。在$ cat euclid.py

from scipy.spatial.distance import euclidean

from itertools import combinations

lines = ['HETATM 1 H10 XSHQ 0 10.139 2.231 0.091 1.00 0.00 H',

'HETATM 2 N1 XSHQ 0 9.641 1.386 -0.104 1.00 0.00 N',

'HETATM 3 H9 XSHQ 0 9.773 1.133 -1.063 1.00 0.00 H',

'HETATM 4 C1 XSHQ 0 8.245 1.531 0.230 1.00 0.00 H']

H_lines = (line for line in lines if line[-1]=='H')

H_lists = (line.split() for line in H_lines)

H_data = ((int(tok[1]), [float(x) for x in tok[5:8]]) for tok in H_lists)

H_dist = {(i[0], j[0]):euclidean(i[1], j[1])

for i, j in combinations(H_data, 2)}

for m, n in H_dist:

print('Distance between points %d and %d is %.6f'%(

m, n, H_dist[m, n]))

$ python3 euclid.py

Distance between points 1 and 3 is 1.634404

Distance between points 1 and 4 is 2.023995

Distance between points 3 and 4 is 2.040842

$

總結

以上是生活随笔為你收集整理的python xyz_python中xyz坐标的欧几里德距离的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。