รูปร่าง ชนิดข้อมูล และการทำดัชนี
อ่านรูปร่างของเทนเซอร์และตัดแบ่งข้อมูลภายใน
รูปร่าง ชนิดข้อมูล และการทำดัชนี เป็นบทเรียน Deep Learning Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Deep Learning Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Deep Learning Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Tensors Are Just Numbers in a Grid
A tensor is a box of numbers arranged in rows, columns, or deeper. Everything in deep learning flows through them.
Shape Describes the Layout
The shape tells you how many values sit along each dimension. Read it like dimensions of a box: rows by columns. 📦
Check Shape with .shape
Ask any tensor for its .shape and PyTorch hands you the size of every dimension in order.
import torch
x = torch.tensor([[1, 2, 3], [4, 5, 6]])
print(x.shape) # torch.Size([2, 3])Dimensions Count with .ndim
The number of dimensions is the tensor's rank. A scalar is 0, a vector is 1, a matrix is 2, and images go higher.
x = torch.tensor([[1, 2], [3, 4]])
print(x.ndim) # 2Every Tensor Has a Dtype
The dtype is the kind of number stored, like float32 or int64. It controls precision and which math is allowed.
x = torch.tensor([1.0, 2.0, 3.0])
print(x.dtype) # torch.float32Float32 Is the Default for Learning
Most networks train in float32 because gradients need decimals. Integers can't hold the tiny fractional updates.
Cast Between Dtypes
Change a tensor's type with .to() or .float(). This is how you match a model's expected precision.
x = torch.tensor([1, 2, 3])
y = x.to(torch.float32)
print(y.dtype) # torch.float32Indexing Grabs One Value
Indexing uses square brackets to pull out a single element by its position, counting from zero.
x = torch.tensor([10, 20, 30])
print(x[0]) # tensor(10)Two Indices for a Matrix
For a 2D tensor, give a row then a column. The order always follows the shape you saw earlier.
x = torch.tensor([[1, 2, 3], [4, 5, 6]])
print(x[1, 2]) # tensor(6)Slicing Takes a Range
Use a colon to grab a whole slice. start:stop keeps everything up to but not including stop.
x = torch.tensor([10, 20, 30, 40])
print(x[1:3]) # tensor([20, 30])Slice Rows and Columns Together
A lone colon means take all of that dimension. This is how you select a whole column across every row.
x = torch.tensor([[1, 2], [3, 4]])
print(x[:, 0]) # tensor([1, 3])Quick Check
Time to test what shape and indexing really mean.
Recap: Shapes, Dtypes & Indexing
You can now read a tensor's shape, check its dtype, and slice into it. These three skills unlock every tensor operation ahead. 🎉
คำถามที่พบบ่อย
บทเรียน “รูปร่าง ชนิดข้อมูล และการทำดัชนี” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “รูปร่าง ชนิดข้อมูล และการทำดัชนี” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Deep Learning Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Deep Learning Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “รูปร่าง ชนิดข้อมูล และการทำดัชนี”
อ่านรูปร่างของเทนเซอร์และตัดแบ่งข้อมูลภายใน คุณปฏิบัติ Deep Learning Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Deep Learning Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Deep Learning Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน
บทเรียน “รูปร่าง ชนิดข้อมูล และการทำดัชนี” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Deep Learning Academy นี้ได้ไหม
ได้ บทเรียน Deep Learning Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- รูปร่าง ชนิดข้อมูล และการทำดัชนี
- เปลี่ยนรูปร่าง มุมมอง ลดมิติ และเพิ่มมิติ
- กฎการกระจายมิติที่ช่วยลดการวนซ้ำ
- เทนเซอร์สื่อสารกับ NumPy