[問題] Numpy array filter

看板Python作者 (Rossy)時間8年前 (2017/07/25 14:38), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
大家好 最近在學習Python Data Visulization,利用一個叫做is_outlier的函數找出資料裡的outlier: def is_outlier(points, threshold = 3.5): if len(points.shape) == 1: points = points[:,None] median = np.median(points, axis = 0) diff = np.sum((points = median)**2, axis = -1) diff = np.sqrt(diff) med_abs_deviation = np.median(diff) modified_z_score = 0.6745*diff/med_abs/deviation return modified_z_score > threshold x = np.random.randmon(100) x = no.r_[x, -49, 95, 100, -100] filtered = x[~is_outlier(x)] 想請教大家,在函數內的points[:,None]是什麼意思? 還有為何filtered的值會是剔除outlier的numpy array呢? 是因為return modified_z_score > threshold這個判斷式會對整個array裡的值做判斷,然後True的值就放到filtered裡面嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 42.72.117.101 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1500964702.A.539.html

07/26 23:46, , 1F
已解決
07/26 23:46, 1F
文章代碼(AID): #1PTkTUKv (Python)