[英]Group numpy matrix based on value of particular column, only on row indices from given array
我有一個由二進制值組成的 numpy 矩陣。 我也有一個行索引列表。 現在我必須從特定列的值為 1 的矩陣中獲取索引,並且索引必須包含在行索引列表中。 什么是這樣做的有效方法? 我目前正在做:
result = [index for index in np.where(dataset[:, col] == 1)[0] if index in indices]
也許循環遍歷行索引列表會更快,因為您不需要遍歷矩陣的所有行:
result = [index for index in indices if dataset[index, col] == 1]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.