1. 程式人生 > >詭異錯誤二:TypeError: data type not understood

詭異錯誤二:TypeError: data type not understood

若是 code error: 輸出 數據表 zeros blog 三維 strong

如何使用Python產生一個數組,數組的長度為1024,數組的元素全為0?

  • 很簡單啊, 使用zeros(1024) 即可實現!

如何產生一個2×1024的全0矩陣呢?是否是zeros(2,1024) ?

  • 若是上述這種寫法就會出現 TypeError: data type not understood 這種錯誤;
  • 正確的寫法是 zeros((2,1024)),python的二維數據表示要用二層括號來進行表示。

三維數據是否使用三層括號?試一試,果然可以正確輸出!試猜一猜, 下述三層括號中的數字分別代表什麽含義?

In [9]: zeros(((2,2,3)))
Out[
9]: array([[[ 0., 0., 0.], [ 0., 0., 0.]],
[[ 0., 0., 0.], [ 0., 0., 0.]]])

詭異錯誤二:TypeError: data type not understood