0Pricing
Deep Learning Academy · บทเรียน

torch.tensor แรกของคุณ

สร้างเทนเซอร์และพิมพ์รูปร่างกับชนิดข้อมูล

torch.tensor แรกของคุณ เป็นบทเรียน Deep Learning Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Deep Learning Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Deep Learning Academy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Meet the Tensor

A tensor is PyTorch's core data container, a grid of numbers much like a NumPy array but ready to run on a GPU. 🧮

Create One from a List

The simplest way to make a tensor is torch.tensor from a Python list. PyTorch copies your numbers into a fast numerical grid.

x = torch.tensor([1, 2, 3])

Print It Out

Printing a tensor shows its values wrapped in tensor(...), so you always know you are looking at PyTorch data, not a plain list.

print(x)

Shape Describes Structure

The shape tells you the size along each dimension. A flat list of three values has a shape of three.

print(x.shape)

Build a 2D Tensor

Nest lists to make a grid. This matrix has two rows and three columns, so its shape reads as two by three.

m = torch.tensor([[1, 2, 3], [4, 5, 6]])

Dtype Is the Number Type

Every tensor has a dtype, the kind of number it stores. Whole numbers become int64, decimals become float32 by default.

print(x.dtype)

Floats for Training

Networks learn with decimals, so most model data is float32. Add a decimal point and PyTorch picks the float type for you.

y = torch.tensor([1.0, 2.0, 3.0])

Set the Dtype Yourself

You can request a type directly with the dtype argument, which is handy when you need floats from integer input.

z = torch.tensor([1, 2], dtype=torch.float32)

Tensors Full of Zeros

Need a blank tensor of a given size? torch.zeros fills the shape you ask for with zeros, perfect as a starting buffer.

torch.zeros(2, 3)

Random Tensors

Model weights often start random. torch.rand gives a tensor of the shape you choose, filled with values between zero and one.

torch.rand(2, 3)

Count the Dimensions

The number of dimensions is the tensor's rank. Read it with .ndim: a vector is rank one, a matrix is rank two.

print(m.ndim)

Quick Check

Reason about the shape of a nested-list tensor.

Recap

You created tensors from lists, read their shape and dtype, and made zeros and random grids. This is the data deep learning runs on. ✅

คำถามที่พบบ่อย

บทเรียน “torch.tensor แรกของคุณ” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “torch.tensor แรกของคุณ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Deep Learning Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Deep Learning Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “torch.tensor แรกของคุณ”

สร้างเทนเซอร์และพิมพ์รูปร่างกับชนิดข้อมูล คุณปฏิบัติ Deep Learning Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Deep Learning Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Deep Learning Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน

บทเรียน “torch.tensor แรกของคุณ” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Deep Learning Academy นี้ได้ไหม

ได้ บทเรียน Deep Learning Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. ติดตั้ง PyTorch และตรวจสอบการนำเข้า
  2. CPU กับ GPU กับ MPS: เลือกอุปกรณ์
  3. โน้ตบุ๊ก สคริปต์ และค่าเริ่มต้นที่ทำซ้ำได้
  4. torch.tensor แรกของคุณ
← กลับไปที่ Deep Learning Academy