Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Indexing in Theano

How can I index a matrix in Theano by a vector of indices?
More precisely, say that:

  • v has type theano.tensor.vector (e.g. [0,2])
  • A has type theano.tensor.matrix (e.g. [[1,0,0], [0,1,0], [0,0,1]])

The desired result is [[1,0,0], [0,0,1]].
I mention that my goal is to convert a list of indices into a matrix of one-hot row vectors, where the indices indicate the hot position. My initial attempt was to let A = theano.tensor.eye and index it using the vector of indices.

like image 233
John Jaques Avatar asked Jun 12 '14 11:06

John Jaques


1 Answers

You can do:

A[v]

It will do what you want.

like image 180
nouiz Avatar answered Sep 23 '22 11:09

nouiz