user3688217
user3688217

Reputation: 588

Making a matrix from several vectors

Is it possible to make a Matrix out of several vectors in theano?

like:

vector1, vector2, vector3 = theano.tensor.vector()
Matrix = [vector1, vector2, vector3]

similar to the numpy operation:

Matrix = numpy.asarray([vector1, vector 2, vector3])

Upvotes: 2

Views: 356

Answers (1)

Daniel Renshaw
Daniel Renshaw

Reputation: 34187

You can use theano.tensor.stack.

Here's a working example:

import theano
import theano.tensor as tt

vector1, vector2, vector3 = tt.vectors(3)
matrix = tt.stack(vector1, vector2, vector3)
f = theano.function([vector1, vector2, vector3], matrix)
print f([1, 2, 3], [4, 5, 6], [7, 8, 9])

where prints

[[ 1.  2.  3.]
 [ 4.  5.  6.]
 [ 7.  8.  9.]]

Upvotes: 3

Related Questions