[程式] Python寫的Yate's Algorithm

看板Statistics作者 (烏木)時間16年前 (2009/08/04 01:52), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
------------------------------------------------------------------------ [軟體程式類別]: Python [程式問題]: 實作Yate's Algorithm [軟體熟悉度]: [問題敘述]: 實作Yate's Algorithm 輸入2^k factorial design the 結果 輸出Yates Algorithm 的結果 *[m [程式範例]: from array import array import math def YatesAlgorithm(dataArray): dataLength = len(dataArray) effectsNum = math.log(dataLength, 2) dataNew = dataArray[:] if ((effectsNum - int(effectsNum)) != 0.0): print("The length of data array must be 2^k") else: for i in range(1, int(effectsNum)+1): dataTmp = dataNew[:] for j in range(1, int(dataLength/2)+1): temp1 = dataNew[2*(j-1)] + dataNew[2*j-1] temp2 = dataNew[2*j-1] - dataNew[2*(j-1)] dataTmp[j-1] = temp1 dataTmp[int(dataLength/2)+j-1] = temp2 print(dataNew) dataNew = dataTmp[:] return(dataNew) ----------------------------------------------------------------------------- 謝謝指教 -- 凡發生之事必合理 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 67.221.66.201
文章代碼(AID): #1AToFF43 (Statistics)