Python resize() <np.函式> 與 <陣列物件.函式> 相關問題
np.resize(a,new_shape)與a.resize(new_shape,refcheck=False) 兩者在超過總元素值時會自動填入。 a.resize(new_shape,refcheck=False)會填充0 np.resize(a,new_shape)會重複填充原始矩陣的內容,實現形狀大小的自動調整而不報錯 兩者程式碼都是使用resize()函式為甚麼會有不一樣的表示? 
回答列表
-
2021/01/25 下午 04:26Matthew Huang贊同數:0不贊同數:0留言數:0
根據報錯訊息,我猜是因為refcheck=Ture,所以resize不會再幫你自動填充的關係,取而代的是跟你報錯
-
2021/01/25 下午 04:29張維元 (WeiYuan)贊同數:2不贊同數:0留言數:0
嗨,你好
在 [文件](https://numpy.org/doc/stable/reference/generated/numpy.resize.html) 是這樣寫的: If the new array is larger than the original array, then the new array is filled with repeated copies of a. **Note that this behavior is different from a.resize(new_shape) which fills with zeros instead of repeated copies of a**. 至於為什麼要這樣設計,可能有他們當時的考量(文件並沒有特別些出來),無從揣測。
嗨,你好,我是維元,持續在不同的平台發表對 #資料科學、 #網頁開發 或 #軟體職涯 相關的文章。如果對於內文有疑問都歡迎與我們進一步的交流,都可以追蹤我的 Facebook 或 技術部落格 ,也會不定時的舉辦分享活動,一起來玩玩吧 ヽ(●´∀`●)ノ