numpy模塊(2)

1、利用布爾值來取元素 import numpy as np mask = np.array([1,0,1],dtype=bool) # 1表示取對應的元素,0表示不取 arr = np.array([[1,2,3],[4,5,6],[7,8,9]]) print(arr[mask,2]) print(arr[:,mask]) 運行結果: [3 9] [[1 3] [4 6] [7 9]] 一
相關文章
相關標籤/搜索