python依赖平台吗_在Python中创建快速循环最依赖于平台和pythonversion的方法是什么?...
我正在用Python編寫一個科學(xué)應(yīng)用程序,其核心是一個處理器密集型的循環(huán)。我希望盡可能地優(yōu)化這一點(diǎn),將給最終用戶帶來的不便降到最低,他們可能會將其作為Python腳本的未編譯集合,并將使用Windows、Mac和(主要是Ubuntu)Linux。在
它目前是用Python編寫的,帶有少量NumPy,我已經(jīng)包含了下面的代碼。在是否有一個不需要編譯的快速解決方案?這似乎是保持平臺獨(dú)立性的最簡單方法。在
如果使用像Pyrex這樣需要編譯的東西,有沒有一種簡單的方法可以捆綁許多模塊,并讓Python根據(jù)檢測到的OS和Python版本在它們之間進(jìn)行選擇?有沒有一種簡單的方法來構(gòu)建模塊集合,而不需要訪問每一個Python版本的每個系統(tǒng)?在
是否有一種方法特別適合于多處理器優(yōu)化?在
(如果你感興趣的話,這個循環(huán)是通過把附近大量磁性離子的貢獻(xiàn)加在一起來計算晶體內(nèi)某個給定點(diǎn)的磁場,這些離子被視為微小的條形磁鐵。基本上是these的一個巨大的和。)# calculate_dipole
# -------------------------
# calculate_dipole works out the dipole field at a given point within the crystal unit cell
# ---
# INPUT
# mu = position at which to calculate the dipole field
# r_i = array of atomic positions
# mom_i = corresponding array of magnetic moments
# ---
# OUTPUT
# B = the B-field at this point
def calculate_dipole(mu, r_i, mom_i):
relative = mu - r_i
r_unit = unit_vectors(relative)
#4pi / mu0 (at the front of the dipole eqn)
A = 1e-7
#initalise dipole field
B = zeros(3,float)
for i in range(len(relative)):
#work out the dipole field and add it to the estimate so far
B += A*(3*dot(mom_i[i],r_unit[i])*r_unit[i] - mom_i[i]) / sqrt(dot(relative[i],relative[i]))**3
return B
總結(jié)
以上是生活随笔為你收集整理的python依赖平台吗_在Python中创建快速循环最依赖于平台和pythonversion的方法是什么?...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: Python小练习1:.txt文件常用读
- 下一篇: java jdbc is一个会话_jav
