2017-07-02 114 views

回答

0

就我所知,您可以使用numpy索引來替換大於某個閾值的所有元素。

雖然,我不確定這是最快的方法。

threshold = 10 # for example 
some_array[some_array > threshold] = threshold 
0

嘗試numpy.where:

from numpy import where 

    Y = where(X> treshold, threshold,X) 

其中適用,if語句在ufunc的方式與其中(條件,如果是真的,否則)

相關問題