開始使用 PyTorch 張量
張量(tensor)是 PyTorch 的核心資料結構,也是深度學習的基礎。它類似 NumPy 陣列,但有其獨特功能。
這裡有一個名為 temperatures 的 Python 清單,包含兩個氣象站的每日讀數。試著把它轉換成張量吧!
本練習屬於課程
使用 PyTorch 的深度學習入門
練習說明
- 先匯入
torch。 - 從 Python 清單
temperatures建立一個「張量」。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import PyTorch
____
temperatures = [[72, 75, 78], [70, 73, 76]]
# Create a tensor from temperatures
temp_tensor = torch.____(____)
print(temp_tensor)