หน้ากากบูลีนสำหรับการเลือก
กรองค่าด้วยเงื่อนไข
หน้ากากบูลีนสำหรับการเลือก เป็นบทเรียน Data Science Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Data Science Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Data Science Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Compare a Whole Array
Write a comparison and NumPy applies it to every element at once. The result is a boolean array of True and False values.
a = np.array([5, 12, 7, 20])
a > 10 # [False True False True]That Result Is a Mask
This array of True and False is a mask. Each position marks whether that element passed your condition.
Filter With the Mask
Put the mask in square brackets to keep only the True positions. NumPy returns just the elements that matched.
a[a > 10] # [12 20]One Line, No Loop
This replaces a manual loop with one expression. Boolean filtering is faster to write and far faster to run on big arrays.
Combine Conditions
Join masks with & for and and the pipe for or. Each condition must sit inside its own parentheses.
a[(a > 5) & (a < 20)] # [12 7]Mind the Parentheses
Without parentheses around each condition, Python applies operators in the wrong order and raises an error. Wrap every comparison.
Flip With the Tilde
The ~ operator inverts a mask, turning True into False. Use it to select everything that did not match your condition.
a[~(a > 10)] # [5 7]Count the Matches
Booleans act like 1 and 0, so sum on a mask counts how many elements passed. It is a quick way to size a subset.
(a > 10).sum() # 2Check Any or All
Use any to ask if at least one element matched, and all to ask if every element did. Both return a single True or False.
(a > 0).all() # TrueAssign Through a Mask
A mask can target elements for assignment, not just reading. Here every value above 10 is capped at 10 in place.
a[a > 10] = 10Masks Power Data Cleaning
From dropping outliers to fixing bad entries, masks are how data scientists select and edit exactly the values they care about.
Quick Check
You want values both above 5 and below 20.
Mask Recap
You built boolean masks, filtered and counted with them, combined conditions safely, and even assigned through them. That is selection mastery. ✨
คำถามที่พบบ่อย
บทเรียน “หน้ากากบูลีนสำหรับการเลือก” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “หน้ากากบูลีนสำหรับการเลือก” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ 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 ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- ปรับรูปร่างและทำอาร์เรย์ให้แบน
- ผลรวม ค่าเฉลี่ย และเคล็ดลับแกน
- หน้ากากบูลีนสำหรับการเลือก
- ตัวเลขสุ่มและเมล็ดสุ่ม