0Pricing
Data Science Academy · บทเรียน

รูปร่าง ขนาด และ dtype

อ่านโครงสร้างภายในของอาร์เรย์

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

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

Read the Array's Anatomy

Every array carries metadata about itself. Three labels tell you almost everything: its shape, its size, and its dtype. Let's read each one. 🔍

Shape: Rows and Columns

The shape is a tuple of dimension lengths. A 3-by-4 grid reports (3, 4): three rows down, four columns across.

a = np.zeros((3, 4))
a.shape  # (3, 4)

Shape Tells You the Layout

Shape is your first sanity check. If a model expects (100, 5) and you hand it (5, 100), the shape mismatch is where bugs hide.

ndim: How Many Dimensions

The ndim attribute counts dimensions. A flat row is 1, a table is 2, a stack of tables is 3. It is just the length of the shape.

a.ndim  # 2

Size: Total Element Count

The size is the total number of elements, the product of every shape value. A (3, 4) array has a size of 12.

a.size  # 12

dtype: The One Shared Type

The dtype names the single type all elements share, like int64 or float64. It controls both precision and memory use.

np.array([1, 2, 3]).dtype  # int64

Choose Your dtype on Purpose

You can set the type yourself with the dtype argument. Use a smaller type like int32 to save memory on huge arrays.

np.array([1, 2, 3], dtype='int32')

dtype Affects Precision

float32 holds fewer decimals than float64. Tiny rounding gaps add up, so pick the type your numbers actually need.

Convert With astype

Already have an array? astype returns a copy in a new type, handy for turning floats into clean integers.

f = np.array([1.0, 2.0])
f.astype('int64')

itemsize: Bytes Per Element

The itemsize tells you bytes per element. Multiply it by size to estimate the array's total memory footprint.

a.itemsize  # 8 for float64

Inspect Before You Compute

Checking shape and dtype first saves hours. They reveal mismatched data and wrong types before a calculation quietly goes wrong. ✅

Quick Check

Let's test your read of an array's shape.

Recap

You can now read an array at a glance: shape for layout, ndim and size for counts, and dtype for the shared type. These four checks catch most bugs early. 🎉

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

บทเรียน “รูปร่าง ขนาด และ dtype” ฟรีหรือไม่

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

คุณจะเรียนรู้อะไรในบทเรียน “รูปร่าง ขนาด และ dtype”

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

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

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

บทเรียน “รูปร่าง ขนาด และ dtype” ใช้เวลานานแค่ไหน

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

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

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

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

  1. จากรายการ Python สู่ ndarray
  2. รูปร่าง ขนาด และ dtype
  3. คณิตศาสตร์แบบเวกเตอร์โดยไม่ใช้ลูป
  4. การทำดัชนีและการตัดแบ่งอาร์เรย์
← กลับไปที่ Data Science Academy