特定の数字を含む行を抽出するためには、numpyをどのように使用すればよいですか?
特定の数字を含む行を取り出すには、numpyの条件インデックスを使用することができます。具体的な手順は次の通りです:
- import numpy as npを使ってください。
- These are the topic options for our group project.
- 結果 = arr[arr[:, column_index] == 5]
- カラムインデックス
- 結果
以下は完全なサンプルコードです。
import numpy as np
# 创建一个示例数组
arr = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
# 提取含有数字5的行
column_index = 1
result = arr[arr[:, column_index] == 5]
print(result)
結果は次の通りです:
[[4 5 6]]