2
我碰到下面的語句:參數(...,-1)在重新整形數組時是什麼意思?
train_set_x.reshape(train_set_x.shape[0], -1).T
的train_set_x
的shape
是:(209, 64, 64, 3)
因此,我認爲,shape[0]
是209
,並且T
是轉置?
我不能理解上面的reshape
聲明嗎?什麼是-1
?
對此非常感謝。
謝謝。
我碰到下面的語句:參數(...,-1)在重新整形數組時是什麼意思?
train_set_x.reshape(train_set_x.shape[0], -1).T
的train_set_x
的shape
是:(209, 64, 64, 3)
因此,我認爲,shape[0]
是209
,並且T
是轉置?
我不能理解上面的reshape
聲明嗎?什麼是-1
?
對此非常感謝。
謝謝。
-1將採取其餘的維度,並將它們壓平成1維。因此,在一個陣列的具有形狀(209, 64, 64, 3)
呼叫的情況下:
arr.reshape(209, -1)
將導致形狀(209, 12288)
或矩陣(209,64×64×3)
>>> a = np.zeros([209, 64, 64, 3])
>>> a.reshape(209, -1).shape
(209, 12288)
如果您的代碼爲64 x 64 RGB圖像,您將最終將每個圖像重新整形爲一個長向量。
此外,請注意,在數組將被重新整形的新形狀中,只能有一個-1。