Wenpeng Yin
2018-06-14 03:45:50 UTC
Hi guys,
I have a very simple code:
import numpy as np
import theano
import theano.tensor as T
sents_id_matrix=T.imatrix() #(2, 4)
repeat_common_input = T.repeat(sents_id_matrix, 3, axis=0)
output = repeat_common_input.reshape((2*3,3))
train_model = theano.function([sents_id_matrix], output)
if __name__ == '__main__':
cost_i= train_model(np.asarray([[1,2,3,4],[5,6,7,8]], dtype='int32'))
print cost_i
Basically I wanted to reshape an input matrix of size (2,4) into (6,4). In
the place "reshape((2*3,3))" I intentionally put a wrong resulting
dimension so as to generate the error info. My question is that the error
is different as I expected:
ValueError: total size of new array must be unchanged
repeat_common_input.reshape((2*3,3))".
However, I thought the dimensionality of "repeat_common_input" should be
(6,4) in stead of the tensor3 -- (2,3,4)
Interesting, if the train_model directly sets "repeat_common_input" as
output, then it is a matrix of (6, 4)
This is a toy code to reproduce my bug. As what exactly the internal shape
is will influence my other operations, such as I planed to do max over some
dimensions, but if a tensor variable has different dimensionality as I
expected, my code will have error.
Thanks for any help.
I have a very simple code:
import numpy as np
import theano
import theano.tensor as T
sents_id_matrix=T.imatrix() #(2, 4)
repeat_common_input = T.repeat(sents_id_matrix, 3, axis=0)
output = repeat_common_input.reshape((2*3,3))
train_model = theano.function([sents_id_matrix], output)
if __name__ == '__main__':
cost_i= train_model(np.asarray([[1,2,3,4],[5,6,7,8]], dtype='int32'))
print cost_i
Basically I wanted to reshape an input matrix of size (2,4) into (6,4). In
the place "reshape((2*3,3))" I intentionally put a wrong resulting
dimension so as to generate the error info. My question is that the error
is different as I expected:
ValueError: total size of new array must be unchanged
Apply node that caused the error: Reshape{2}(Alloc.0, TensorConstant{[6
3]})
Toposort index: 4
Inputs types: [TensorType(int32, 3D), TensorType(int64, vector)]
Inputs shapes: [(2, 3, 4), (2,)]
The error should be due to the line "output =3]})
Toposort index: 4
Inputs types: [TensorType(int32, 3D), TensorType(int64, vector)]
Inputs shapes: [(2, 3, 4), (2,)]
repeat_common_input.reshape((2*3,3))".
However, I thought the dimensionality of "repeat_common_input" should be
(6,4) in stead of the tensor3 -- (2,3,4)
Interesting, if the train_model directly sets "repeat_common_input" as
output, then it is a matrix of (6, 4)
This is a toy code to reproduce my bug. As what exactly the internal shape
is will influence my other operations, such as I planed to do max over some
dimensions, but if a tensor variable has different dimensionality as I
expected, my code will have error.
Thanks for any help.
--
---
You received this message because you are subscribed to the Google Groups "theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to theano-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
---
You received this message because you are subscribed to the Google Groups "theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to theano-users+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.