看板 Python 關於我們 聯絡資訊
如題,一般來說 aaa = [88,99,66,44] print(type(aaa)) aaa = aaa - aaa[0] print(type(aaa)) 會得到: <class 'list'> TypeError: unsupported operand type(s) for -: 'list' and 'int' 不過剛剛我的程式碼有一部分如下 print(type(x_JKR)) x_JKR -= x_JKR[0] print(type(x_JKR)) 結果得到: <class 'list'> <class 'numpy.ndarray'> 我:黑人問號.jpg 我唯一想到的可能是,之前原本是在 x_JKR -= x_JKR[0]之前 先做過 x_JKR = np.array(x_JKR) ,轉換成array後再來扣除首項 後來因為一些問題所以把這轉換過程移到後面去了 不過我也試著對測試用的aaa也做了類似的事,但並沒有導致同樣的結果 用的編輯器是VS Code 模式是jupyter notebook(開在VS Code內) -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.138.53.81 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1693046754.A.C9A.html
lycantrope: 不就list內是numpy.array,計算後自動casting 08/26 19:21
poototo: 留意broadcast 08/27 19:16
fragmentwing: 知道問題是出在broadcast上 只是出錯的方式 會不會 08/28 14:03
fragmentwing: 自己轉成array怎麼好像是隨機的 08/28 14:03
aalexx: 隨機的。大學重修吧 08/29 02:11
s860134: 不是隨機的大哥,你自己的 list 內容裝啥都搞不清楚 09/10 04:39
s860134: 另外 jupyter kernel 是 stateful 的,測試前先restart 09/10 04:42