Theano中的NumPy的a[a < 0] = 0
的等效物(張量變量)是什麼? 我希望我的所有矩陣元素都小於等於零的數字。什麼等於Theano中的[a <0] = 0?
3
A
回答
5
這項工作:
import theano
a=theano.tensor.matrix()
idxs=(a<0).nonzero()
new_a=theano.tensor.set_subtensor(a[idxs], 0)
不要忘記,Theano是一個象徵性的語言。所以變量a在用戶圖中沒有改變。這是新變量new_a包含新值並且仍舊具有舊值。
Theano將優化這個如果可能的話就地工作。
+1
感謝。並且還與「a = T.where(a <0,0,a)」一起工作 –
1
這也適用,並且還可以添加上限限制
import theano
import theano.tensor as T
a = T.matrix()
b = a.clip(0.0)
或者如果你想上限,以及,你可能想嘗試:
b = T.clip(a, 0.0, 1.0)
其中1.0的地方一個人想設置上限。
檢查文件here
相關問題
- 1. iOS - 什麼等價於「stretchableImageWithLeftCapWidth:0 topCapHeight:0」?
- 2. 爲什麼thing [:] [0]等於thing [0] [:]?
- 3. len(a [0])中的[0]代表什麼?
- 4. 爲什麼string ='0'不嚴格等於javascript中的新String('0')
- 5. 什麼是go的等價於argv [0]?
- 6. a [0] = addr&0xff是什麼?
- 7. 爲什麼0.1 * 10-1不等於0?
- 8. 爲什麼+ []或+「」等於0在javascript
- 9. R. as.numeric。 0不等於0
- 10. 什麼是「a」代表字體:0/0 a;
- 11. 什麼是「this.x = x <0?0:x; this.y = y <0?0:y;」意思?
- 12. 當使用指針時,爲什麼'\ 0'等於0?
- 13. Fortran問題0 + 0不等於0
- 14. 等於0時
- 15. 爲什麼`null> = 0 && null <= 0`但不是`null == 0`?
- 16. 「struct a a1 = {0};」不同於「struct a a2 = {5};」爲什麼?
- 17. -0?什麼是-0?
- 18. return v.compareTo(w)<0; 「<0」服務有什麼影響?
- 19. 在Grails GSP中,Spring MVC的<input name =「entity.list [0] .field」>等價於什麼?
- 20. 板子等於0
- 21. $(「#id」)[0]中的[0]是做什麼的?
- 22. 什麼是返回void 0 === i &&(i = 3),0 ===我? (..A ..):(..B ..)呢?
- 23. 這句話做什麼「while(a [i] - != 0)」?
- 24. 爲什麼a [0]會改變?
- 25. 爲什麼最後使用getElementsByTagName(「a」)[0]?
- 26. 爲什麼JavaScript中的「0 === -0」爲true?
- 27. NSUInteger小於0,爲什麼?
- 28. 爲什麼65.6 * 100%10等於9,而不是PHP中的0?
- 29. 爲什麼整數0等於PHP中的一個字符串?
- 30. 什麼是decltype(0 + 0)?
文檔中的相關位置似乎http://deeplearning.net/software/theano/library/tensor/basic.html#indexing –