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

คณิตศาสตร์แบบเวกเตอร์โดยไม่ใช้ลูป

ดำเนินการกับสมาชิกทั่วทั้งอาร์เรย์

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

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

Math on Whole Arrays

With NumPy you rarely write loops for math. You apply an operation to a whole array at once, and every element updates together. ⚡

The Old Loop Way

In plain Python, doubling numbers means looping one by one. It works, but it's verbose and slow for big datasets.

out = []
for x in nums:
    out.append(x * 2)

The Vectorized Way

NumPy collapses that loop into one line. Vectorization means the operation runs across the entire array in fast compiled code.

arr * 2  # every element doubled

Element-Wise by Default

Add two arrays and NumPy pairs them up position by position. This element-wise behavior is the heart of array math.

np.array([1, 2, 3]) + np.array([10, 20, 30])

Scalars Spread Everywhere

Add a single number to an array and it touches every element. NumPy calls this broadcasting the scalar across the whole grid.

np.array([1, 2, 3]) + 100

All the Operators Work

Subtraction, division, and powers all behave element-wise too. One expression transforms a million numbers in an instant.

arr ** 2  # square each element

Universal Functions

NumPy ships fast math helpers called ufuncs. np.sqrt and np.exp run across an entire array without a single loop.

np.sqrt(np.array([1, 4, 9]))  # 1 2 3

Compare Whole Arrays

Comparisons vectorize too. An expression like arr > 5 returns a boolean array, one True or False per element.

np.array([3, 7, 5]) > 5  # F T F

Why It Runs So Fast

Vectorized code pushes the loop down into optimized C. You skip Python's per-step overhead, so the same work finishes far faster. 🚀

Clearer Code, Too

Beyond speed, vectorized math reads like the formula itself. Less code means fewer bugs and an analysis anyone can follow.

celsius = (fahrenheit - 32) * 5 / 9

Think in Arrays

The mindset shift is simple: stop thinking one number at a time and start thinking in whole arrays. That habit unlocks NumPy's power. 🧠

Quick Check

Let's see what vectorized math returns.

Recap

You learned to drop the loop: vectorized math applies operations element-wise across whole arrays, with scalars broadcast and ufuncs for the rest. Faster and clearer. 🎉

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

บทเรียน “คณิตศาสตร์แบบเวกเตอร์โดยไม่ใช้ลูป” ฟรีหรือไม่

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

คุณจะเรียนรู้อะไรในบทเรียน “คณิตศาสตร์แบบเวกเตอร์โดยไม่ใช้ลูป”

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

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

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

บทเรียน “คณิตศาสตร์แบบเวกเตอร์โดยไม่ใช้ลูป” ใช้เวลานานแค่ไหน

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

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

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

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

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