Discussion:
How can I fix this TypeError problem?
Zay Maung Maung Aye
2014-05-28 10:48:19 UTC
Permalink
Hi,

I have computed a theano tensor matrix and I would like to get the bincount
in *each row *of the tensor variable. So I think I'll need either some
types of looping on TensorVariable or getting the values from
TensorVariable into numpy.array.

I am using the theano.scan to loop through each row of the matrix and it
works when I entered *numeric values* to the theano function *predict*. But
my input matrix is a TensorVariable computed from earlier steps and
theano.function does not accept TensorVariable. Is there any way to work
around this problem? Can I extract the values from TheanoVariable as
numpy.array? or is there any way to work directly on the TensorVariable?


X = T.imatrix('X')
results, updates = theano.scan(lambda x_i:
T.argmax(T.extra_ops.bincount(x_i)), sequences=[X])
predict = theano.function(inputs=[X], outputs=[results])

predict(Y)

Y is a TensorVariable from another function.

And the error that I face is:

File "/usr/local/lib/python2.7/dist-packages/theano/tensor/type.py", line
66, in filter
'Expected an array-like object, but found a Variable: '
TypeError: ('Bad input argument to theano function at index 0(0-based)',
'Expected an array-like object, but found a Variable: maybe you are trying
to call a function on a (possibly shared) variable instead of a numeric
array?')

I'm new to theano and I don't know how people approach this type of
problems. Please help.

Thanks.
--
---
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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Olivier Delalleau
2014-05-28 11:11:35 UTC
Permalink
A theano.function works with numeric arrays, not symbolic variables.
Work directly on Y instead of declaring a new variable X, and have predict() take as inputs whatever is needed to compute Y:

results, up = scan(..., sequences=[Y])
predict = function([i1, ..., in], outputs=results, updates=up)

-=- Olivier
Hi,
I have computed a theano tensor matrix and I would like to get the bincount in each row of the tensor variable. So I think I'll need either some types of looping on TensorVariable or getting the values from TensorVariable into numpy.array.
I am using the theano.scan to loop through each row of the matrix and it works when I entered numeric values to the theano function predict. But my input matrix is a TensorVariable computed from earlier steps and theano.function does not accept TensorVariable. Is there any way to work around this problem? Can I extract the values from TheanoVariable as numpy.array? or is there any way to work directly on the TensorVariable?
X = T.imatrix('X')
results, updates = theano.scan(lambda x_i: T.argmax(T.extra_ops.bincount(x_i)), sequences=[X])
predict = theano.function(inputs=[X], outputs=[results])
predict(Y)
Y is a TensorVariable from another function.
File "/usr/local/lib/python2.7/dist-packages/theano/tensor/type.py", line 66, in filter
'Expected an array-like object, but found a Variable: '
TypeError: ('Bad input argument to theano function at index 0(0-based)', 'Expected an array-like object, but found a Variable: maybe you are trying to call a function on a (possibly shared) variable instead of a numeric array?')
I'm new to theano and I don't know how people approach this type of problems. Please help.
Thanks.
--
---
You received this message because you are subscribed to the Google Groups "theano-users" group.
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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Zay Maung Maung Aye
2014-05-28 11:58:10 UTC
Permalink
Is there any way to scan Y without using theano.function?
The values in my Y is not from the input data, these are computed from
other functions so these are already TensorVariables.
And, I do not know the values for function([i1, ..., in]) as these inputs
are coming from other process because I had to do some transformation
before getting Y.

Thanks.
Post by Olivier Delalleau
A theano.function works with numeric arrays, not symbolic variables.
Work directly on Y instead of declaring a new variable X, and have
results, up = scan(..., sequences=[Y])
predict = function([i1, ..., in], outputs=results, updates=up)
-=- Olivier
Hi,
I have computed a theano tensor matrix and I would like to get the
bincount in *each row *of the tensor variable. So I think I'll need
either some types of looping on TensorVariable or getting the values from
TensorVariable into numpy.array.
I am using the theano.scan to loop through each row of the matrix and it
works when I entered *numeric values* to the theano function *predict*.
But my input matrix is a TensorVariable computed from earlier steps and
theano.function does not accept TensorVariable. Is there any way to work
around this problem? Can I extract the values from TheanoVariable as
numpy.array? or is there any way to work directly on the TensorVariable?
X = T.imatrix('X')
T.argmax(T.extra_ops.bincount(x_i)), sequences=[X])
predict = theano.function(inputs=[X], outputs=[results])
predict(Y)
Y is a TensorVariable from another function.
File "/usr/local/lib/python2.7/dist-packages/theano/tensor/type.py", line 66, in filter
'Expected an array-like object, but found a Variable: '
TypeError: ('Bad input argument to theano function at index 0(0-based)',
'Expected an array-like object, but found a Variable: maybe you are trying
to call a function on a (possibly shared) variable instead of a numeric
array?')
I'm new to theano and I don't know how people approach this type of problems. Please help.
Thanks.
--
---
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
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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Olivier Delalleau
2014-05-29 12:10:54 UTC
Permalink
You will need to find a way to track your inputs across transformations, otherwise you will end up with some output variable and no idea how to compute it. You could use the graph-manipulation functions from Theano to recover the inputs but it wouldn't give you their semantics, which you probably need to understand when time comes to call the compiled function on numeric data.

-=- Olivier
Post by Zay Maung Maung Aye
Is there any way to scan Y without using theano.function?
The values in my Y is not from the input data, these are computed from other functions so these are already TensorVariables.
And, I do not know the values for function([i1, ..., in]) as these inputs are coming from other process because I had to do some transformation before getting Y.
Thanks.
A theano.function works with numeric arrays, not symbolic variables.
results, up = scan(..., sequences=[Y])
predict = function([i1, ..., in], outputs=results, updates=up)
-=- Olivier
Hi,
I have computed a theano tensor matrix and I would like to get the bincount in each row of the tensor variable. So I think I'll need either some types of looping on TensorVariable or getting the values from TensorVariable into numpy.array.
I am using the theano.scan to loop through each row of the matrix and it works when I entered numeric values to the theano function predict. But my input matrix is a TensorVariable computed from earlier steps and theano.function does not accept TensorVariable. Is there any way to work around this problem? Can I extract the values from TheanoVariable as numpy.array? or is there any way to work directly on the TensorVariable?
X = T.imatrix('X')
results, updates = theano.scan(lambda x_i: T.argmax(T.extra_ops.bincount(x_i)), sequences=[X])
predict = theano.function(inputs=[X], outputs=[results])
predict(Y)
Y is a TensorVariable from another function.
File "/usr/local/lib/python2.7/dist-packages/theano/tensor/type.py", line 66, in filter
'Expected an array-like object, but found a Variable: '
TypeError: ('Bad input argument to theano function at index 0(0-based)', 'Expected an array-like object, but found a Variable: maybe you are trying to call a function on a (possibly shared) variable instead of a numeric array?')
I'm new to theano and I don't know how people approach this type of problems. Please help.
Thanks.
--
---
You received this message because you are subscribed to the Google Groups "theano-users" group.
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.
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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
shyam krishna khadka
2017-05-17 10:39:32 UTC
Permalink
Post by Zay Maung Maung Aye
Hi,
I have computed a theano tensor matrix and I would like to get the
bincount in *each row *of the tensor variable. So I think I'll need
either some types of looping on TensorVariable or getting the values from
TensorVariable into numpy.array.
I am using the theano.scan to loop through each row of the matrix and it
works when I entered *numeric values* to the theano function *predict*.
But my input matrix is a TensorVariable computed from earlier steps and
theano.function does not accept TensorVariable. Is there any way to work
around this problem? Can I extract the values from TheanoVariable as
numpy.array? or is there any way to work directly on the TensorVariable?
X = T.imatrix('X')
T.argmax(T.extra_ops.bincount(x_i)), sequences=[X])
predict = theano.function(inputs=[X], outputs=[results])
predict(Y)
Y is a TensorVariable from another function.
File "/usr/local/lib/python2.7/dist-packages/theano/tensor/type.py",
line 66, in filter
'Expected an array-like object, but found a Variable: '
TypeError: ('Bad input argument to theano function at index 0(0-based)',
'Expected an array-like object, but found a Variable: maybe you are trying
to call a function on a (possibly shared) variable instead of a numeric
array?')
I'm new to theano and I don't know how people approach this type of
problems. Please help.
Thanks.
--
---
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.
Loading...