1

I was wondering how to make a 5D tensor in Theano.

Specifically, I tried dtensor = T.TensorType('float32', (False,)*5). However, the only issue is that dtensor.shapereturns: AttributeError: 'TensorType' object has no attribute 'shape'

Whereas if I used a standard tensor type likedtensor = T.tensor3('float32'), I don't get this issue when I call dtensor.shape. Is there a way to have this not be an issue with a 5D tensor in Theano?

Amir
  • 10,600
  • 9
  • 48
  • 75
user19346
  • 303
  • 3
  • 9

2 Answers2

1

Theano variables do not have explicit shape information since they are symbolic variables, not numerical. Even dtensor3 = T.tensor3(T.config.floatX) does not have an explicit shape. When you type dtensor3.shape you'll get an object Shape.0 but when you do dtensor3.shape.eval() to get its value you'll get an error.

For both cases however, dtensor.ndim works and prints out 5 and 3 respectively.

Amir
  • 10,600
  • 9
  • 48
  • 75
  • Thanks for the response! I guess I was more asking if there is a way to specify dtensor as a 5D tensor in order for dtensor.shape to not return AttributeError: 'TensorType' object has no attribute 'shape'? – user19346 Dec 28 '15 at 00:10
  • Well although both variables are symbolic variables and they both do not have any real **shape** but I myself am confused on why the first one does not even have the attribute shape. I am going to do an investigation on it and will post the results when found a clue. – Amir Dec 28 '15 at 00:24
  • I think I know why. dtensor.shape does not work, but dtensor().shape does in fact work. – user19346 Dec 28 '15 at 05:16
  • @user19346 so what is the reason for it? – Amir Dec 28 '15 at 10:25
1
dtensor = T.TensorType('float32',(False,)*5) 

only calls the function TensorType. In order to use the attribute dtensor.shape you need to make it an object. You can do it by:

dtensor = T.TensorType('float32',(False,)*5) ()

You can specify the name inside the parenthesis at the end if you wish.