3
A
回答
3
花了一點挖,但這裏是爲threshold
代碼(scipy/stats/mstats_basic.py
):
def threshold(a, threshmin=None, threshmax=None, newval=0):
a = ma.array(a, copy=True)
mask = np.zeros(a.shape, dtype=bool)
if threshmin is not None:
mask |= (a < threshmin).filled(False)
if threshmax is not None:
mask |= (a > threshmax).filled(False)
a[mask] = newval
return a
但在此之前,我發現,我反向從文檔設計的它:
例陣列從文檔:
In [152]: a = np.array([9, 9, 6, 3, 1, 6, 1, 0, 0, 8])
In [153]: stats.threshold(a, threshmin=2, threshmax=8, newval=-1)
/usr/local/bin/ipython3:1: DeprecationWarning: `threshold` is deprecated!
stats.threshold is deprecated in scipy 0.17.0
#!/usr/bin/python3
Out[153]: array([-1, -1, 6, 3, -1, 6, -1, -1, -1, 8])
建議的更換
In [154]: np.clip(a,2,8)
Out[154]: array([8, 8, 6, 3, 2, 6, 2, 2, 2, 8])
....
剪切到最大或最小是有道理的;另一方面,閾值將所有超出邊界的值轉換爲其他值,例如0或-1。聽起來不太有用。但是,這並不難實現:
In [156]: mask = (a<2)|(a>8)
In [157]: mask
Out[157]: array([ True, True, False, False, True, False, True, True, True, False], dtype=bool)
In [158]: a1 = a.copy()
In [159]: a1[mask] = -1
In [160]: a1
Out[160]: array([-1, -1, 6, 3, -1, 6, -1, -1, -1, 8])
這是基本相同,我引用的代碼,只有在它如何處理None
情況下的最小或最大不同。
+0
謝謝。所以看起來np.clip並不是'threshold'的直接替代 – user15964
0
對於它的價值,np.clip是直接替換的門檻,如果使用得當:
np.clip(array-threshold,0,1)
相關問題
- 1. 如何找到棄用方法的替代品?
- 2. 如何從我的wordpress代碼替換棄用的函數?
- 3. error_messages_for在ruby中已棄用 - 我如何找到替換項?
- 4. 替代線性代數的scipy和numpy?
- 5. 如何棄用Python函數?
- 6. 如何用新的Blob構造函數替換棄用的BlobBuilder?
- 7. 我在哪裏可以找到java中的棄用項目的替代?
- 8. 在IntelliJ IDEA中,哪裏可以找到棄用的方法的替代方法?
- 9. 替代棄用功能mysql_connect
- 10. 替代已棄用的WebResourceLoadDelegate
- 11. 替代addPreferencesFromResource其棄用
- 12. iTextSharp OcspClientBouncyCastle構造函數已棄用,替代項是什麼?
- 13. 對於MPAndroidChart已棄用的setDrawCubic()的替代函數是什麼?
- 14. 如何使用numpy(和scipy)查找函數的所有零?
- 15. 你如何放棄替代JRE課程?
- 16. 在EPD中使用SciPy函數免費
- 17. jQuery找到location.href並用函數替換
- 18. 如何在代碼塊中找到函數或方法庫
- 19. Scipy curvefit RuntimeError:找不到最佳參數:函數調用次數達到maxfev = 1000
- 20. hbase中的HTableDescriptor(表)已被棄用,替代方案如何?
- 21. 我在哪裏可以找到TMonitor(Delphi 7)或者如何使用替代函數替換它?
- 22. 函數``preg_match()`函數在下面的代碼中如何替換`eregi()`函數?
- 23. 如何使用scipy集成到函數的矢量
- 24. 棄用:函數eregi()已棄用,如何解決此錯誤?
- 25. fftpack中缺少scipy函數
- 26. 使用Scipy/Python從已知輸出中查找未知函數
- 27. 'WebSocket.URL'已棄用。請使用'WebSocket.url'代替
- 28. .dynamicType已棄用。使用'type(of ...)'代替
- 29. XMLHttpRequest已棄用。代替使用什麼?
- 30. MapDB棄用函數
由於文檔中提到剛剛使用'numpy.clip()' - 這裏的談話上的[' scipy'列表](https://mail.scipy.org/pipermail/scipy-dev/2015-July/020844.html) – AChampion
@AChampion謝謝!但在我看來,numpy.clip是不同的。例如,如何使小數字零? numpy.clip只能剪輯到間隔邊緣 – user15964
如果你有一個數組'a',那麼'a [a