2014-09-11 104 views
2

我有張量,我通過展平將其轉換爲向量,現在我想刪除此向量中的重複值。我怎樣才能做到這一點? nano中的numpy.unique()等價於什麼?Theano在張量中獲得唯一值

x1 = T.itensor3('x1') 
y1 = T.flatten(x1) 
#z1 = T.unique() How do I do this? 

For e.g. my tensor may be : [1,1,2,3,3,4,4,5,1,3,4] 
and I want : [1,2,3,4,5] 

回答

3

編輯:這是現在市面上Theano:http://deeplearning.net/software/theano/library/tensor/extra_ops.html#theano.tensor.extra_ops.Unique

這個問題也問theano用戶的郵件列表。結論是,這是Theano中沒有包含的函數NumPy函數之一。由於他不需要畢業,它可以快速包裝。以下是一個期望輸出與輸入相同的示例。

from theano.compile.ops import as_op 


@as_op(itypes=[theano.tensor.imatrix], 
     otypes=[theano.tensor.imatrix]) 
def numpy_unique(a): 
    return numpy.unique(a) 

更多DOC約as_op可以在這裏找到:http://deeplearning.net/software/theano/tutorial/extending_theano.html#as-op-example