看板 Python 關於我們 聯絡資訊
程式碼如下 import numpy as np a=np.zeros(5) ds=[1/2,-1/2] for m in range(1,5): for a[m] in zip (ds): print (m,a[m]) 我要將ds裡面可能的值放進a[m]裡 也就是出來希望是 1,1/2 1,-1/2 2,1/2 2.-1/2 等等 那要用甚麼function才能做到,謝謝(是用python3.0) -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.112.4.209 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1492580763.A.0EC.html
tn00364361: python3.0? 04/20 08:46
ides13: 這是你要的嗎?http://codepad.org/fiC69x08 04/20 19:53
HenryLiKing: 如果只由+-1/2的話可以用-的n次方做呀 04/21 17:15
anyonred: ieds13,我是要把數值給a[m],不是string給a[m] 04/21 18:02
anyonred: 我後面要做的計算是total+=cos(a[1]+a[2]+...a[m]) 04/21 18:04
anyonred: 就是要cos(1/2+a[2]..)+cos(-1/2+a[2]..),然後a[2]再用 04/21 18:06
anyonred: 1/2,-1/2帶入,所以應該會有2^m個不同的cos要相加 04/21 18:07
ides13: 把'a拿掉就是數值了。 04/22 18:32
Fungshui: 你不如寫算式還比較能看得懂,跟本沒人知道你要表達什麼 04/22 23:22