الأقنعة المنطقية للاختيار
رشّح القيم باستخدام الشروط.
الأقنعة المنطقية للاختيار درس مجاني في Data Science Academy على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 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. ✨
الأسئلة الشائعة
هل درس «الأقنعة المنطقية للاختيار» مجاني؟
نعم — نص درس «الأقنعة المنطقية للاختيار» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Data Science Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Data Science Academy 4 دروس في المجموع.
ماذا ستتعلم في «الأقنعة المنطقية للاختيار»؟
رشّح القيم باستخدام الشروط. تتمرن على Data Science Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Data Science Academy؟
لا تُشترط خبرة سابقة. Data Science Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.
كم من الوقت يستغرق درس «الأقنعة المنطقية للاختيار»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Data Science Academy هذا؟
نعم. كل درس في Data Science Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- إعادة تشكيل المصفوفات وتسطيحها
- الجمع والمتوسط وحيلة المحور
- الأقنعة المنطقية للاختيار
- الأرقام العشوائية والبذور