0Pricing
Data Science Academy · レッスン

選択に使うブールマスク

条件で値をフィルタリングします

「選択に使うブールマスク」はCoddyKit上の無料Data Science Academyレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これは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()   # 2

Check 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()   # True

Assign 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] = 10

Masks 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時間対応のAIチューター)、Data Science Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Data Science Academyコースには全4レッスンが含まれています。

「選択に使うブールマスク」で何を学びますか?

条件で値をフィルタリングします ブラウザで直接実行するハンズオンコードでData Science Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Data Science Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのData Science Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。

「選択に使うブールマスク」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このData Science Academyレッスンでコードを書いて実行できますか?

はい。すべてのData Science Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. 配列の形状変更と平坦化
  2. Sum、Mean、Axisの活用
  3. 選択に使うブールマスク
  4. 乱数とシード
← Data Science Academyに戻る