logo
Loading...

Python resize() <np.函式> 與 <陣列物件.函式> 相關問題 - Cupoy

np.resize(a,new_shape)與a.resize(new_shape,refcheck...

resize()

Python resize() <np.函式> 與 <陣列物件.函式> 相關問題

2021/01/25 下午 03:02
Numpy 陣列中不同的資料型態
李仁傑
觀看數:36
回答數:2
收藏數:3
resize()

np.resize(a,new_shape)與a.resize(new_shape,refcheck=False) 兩者在超過總元素值時會自動填入。 a.resize(new_shape,refcheck=False)會填充0 np.resize(a,new_shape)會重複填充原始矩陣的內容,實現形狀大小的自動調整而不報錯 兩者程式碼都是使用resize()函式為甚麼會有不一樣的表示? ![D02error3.png](http://kwassistfile.cupoy.com/00000177384CBD74000000686375706F795F72656C656173655155455354/1611222124063/large)

回答列表

  • 2021/01/25 下午 04:26
    Matthew 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技術部落格 ,也會不定時的舉辦分享活動,一起來玩玩吧 ヽ(●´∀`●)ノ