[英]Indexing matrix with values from vector in theano
I'm working on a cost function in theano and faced the following problem: I have a matrix M (say [[3,4],[5,6]]
), a vector v ( [0,1]
) and I would like to get the vector of entries in M corresponding to the indexes contained in v (here [3,6]
). 我正在theano中处理成本函数,并遇到以下问题:我有一个矩阵M(例如
[[3,4],[5,6]]
),向量v( [0,1]
)和I想要获取M中与v中包含的索引相对应的条目的矢量(此处[3,6]
)。 Is there a command to do exactly that? 有命令可以做到这一点吗?
Edit: I ended up doing the following : M[T.arange(v.shape[0]), v], where T.arange(v.shape[0]) is just a vector which entries are integers in the range of the length of v. M needed to be indexed with a list of two vectors 编辑:我结束了以下操作:M [T.arange(v.shape [0]),v],其中T.arange(v.shape [0])只是一个向量,其中的项是以下范围内的整数v。M的长度需要用两个向量的列表来索引
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.