การตรวจสอบและบวก tensor
ขณะเก็บข้อมูลอุณหภูมิ พบว่าค่าที่อ่านได้คลาดเคลื่อนไปสององศา ให้บวกสององศาเข้าไปใน tensor temperatures โดยตรวจสอบ shape และชนิดข้อมูลของ tensor ด้วย torch ก่อน เพื่อให้แน่ใจว่าเข้ากันได้กับ tensor adjustment
ไลบรารี torch และ tensor temperatures ถูกโหลดไว้ให้แล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Deep Learning เบื้องต้นด้วย PyTorch
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
adjustment = torch.tensor([[2, 2, 2], [2, 2, 2]])
# Display the shape of the adjustment tensor
print("Adjustment shape:", adjustment.____)
# Display the type of the adjustment tensor
print("Adjustment type:", adjustment.____)
print("Temperatures shape:", temperatures.shape)
print("Temperatures type:", temperatures.dtype)