Discussion:
[theano-users] Theano dot function has different output than Numpy's
DL_user
2018-10-02 21:55:09 UTC
Permalink
Why do these two functions have different outputs, even both of them
defined from numpy's dot() function:

x = T.dmatrix('x')

y = T.dvector('y')

z = np.dot(x,y)

f = theano.function([x,y],z)

f([[1,2,3],[4,5,6]],[7,8,9])
Out[31]:
array([[ 7., 16., 27.],
[28., 40., 54.]])

np.dot([[1,2,3],[4,5,6]],[7,8,9])
Out[32]: array([ 50, 122])
--
---
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.
Buruk Aregawi
2018-10-02 22:59:13 UTC
Permalink
It seems that np.dot is interpreting this as the more standard A*x where A
is a 2x3 matrix and x is a 3 dimensional vector. Where as theano is
interpreting it is X*A where X is a 3x1 matrix and A is a 2x3 matrix.
If you do
z = T.dot(x,y)
instead of
z = np.dot(x,y)
they will both work the same and the theano function will interpret it as
the standard A*x.
Post by DL_user
Why do these two functions have different outputs, even both of them
x = T.dmatrix('x')
y = T.dvector('y')
z = np.dot(x,y)
f = theano.function([x,y],z)
f([[1,2,3],[4,5,6]],[7,8,9])
array([[ 7., 16., 27.],
[28., 40., 54.]])
np.dot([[1,2,3],[4,5,6]],[7,8,9])
Out[32]: array([ 50, 122])
--
---
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.
DL_user
2018-10-02 23:40:23 UTC
Permalink
I would think z=np.dot(x,y) is more meaningful but anyway apparently dot()
has different meanings in Theano's world.

thanks
Post by Buruk Aregawi
It seems that np.dot is interpreting this as the more standard A*x where A
is a 2x3 matrix and x is a 3 dimensional vector. Where as theano is
interpreting it is X*A where X is a 3x1 matrix and A is a 2x3 matrix.
If you do
z = T.dot(x,y)
instead of
z = np.dot(x,y)
they will both work the same and the theano function will interpret it as
the standard A*x.
Post by DL_user
Why do these two functions have different outputs, even both of them
x = T.dmatrix('x')
y = T.dvector('y')
z = np.dot(x,y)
f = theano.function([x,y],z)
f([[1,2,3],[4,5,6]],[7,8,9])
array([[ 7., 16., 27.],
[28., 40., 54.]])
np.dot([[1,2,3],[4,5,6]],[7,8,9])
Out[32]: array([ 50, 122])
--
---
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.
Buruk Aregawi
2018-10-03 00:04:23 UTC
Permalink
I believe in Theano world, "dot" is only meant for vector-to-vector dot
products. Where as in Numpy world, it as an overloaded operator/function
that is sometimes a matrix-vector product, a matrix-matrix product or a
vector-vector product depending on the input.
Post by DL_user
I would think z=np.dot(x,y) is more meaningful but anyway apparently dot()
has different meanings in Theano's world.
thanks
Post by Buruk Aregawi
It seems that np.dot is interpreting this as the more standard A*x where
A is a 2x3 matrix and x is a 3 dimensional vector. Where as theano is
interpreting it is X*A where X is a 3x1 matrix and A is a 2x3 matrix.
If you do
z = T.dot(x,y)
instead of
z = np.dot(x,y)
they will both work the same and the theano function will interpret it as
the standard A*x.
Post by DL_user
Why do these two functions have different outputs, even both of them
x = T.dmatrix('x')
y = T.dvector('y')
z = np.dot(x,y)
f = theano.function([x,y],z)
f([[1,2,3],[4,5,6]],[7,8,9])
array([[ 7., 16., 27.],
[28., 40., 54.]])
np.dot([[1,2,3],[4,5,6]],[7,8,9])
Out[32]: array([ 50, 122])
--
---
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Buruk Aregawi
2018-10-04 01:17:16 UTC
Permalink
One correction above for posterity. The Theano version you posted, f =
theano.function([x,y], np.dot(x, y)), does two vector-vector dot products.
So it interprets your input matrix as two separate vectors and separately
does a dot of each of them with the input vector, y. Also, note that the
vectors from the first argument, the vectors from x, is considered a column
vector and the second argument, y, is considered a row vector, which is not
the case in numpy.
--
---
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...