Can anyone explain me the output of following python code:
from theano import tensor as T
from theano import function, shared
a, b = T.dmatrices('a', 'b')
diff = a - b
abs_diff = abs(diff)
diff_squared = diff ** 2
f = function([a, b], [diff, abs_diff, diff_squared])
print f([[1, 1], [1, 1]], [[0, 1], [2, 3]])
print f( [ [1,1],[1,1] ],
[ [0,1],[2,3] ])
Output: [ [[ 1., 0.], [-1., -2.]],
[[ 1., 0.], [ 1., 2.]],
[[ 1., 0.], [ 1., 4.]]]
TensorFlow execution speed is slow when compared to Theano. But in the case of handling the tasks which require multiple GPU TensorFlow is faster. Theano performs tasks way faster than TensorFlow. Mainly the tasks that require a single GPU will run faster in Theano.
Theano is a Python library for fast numerical computation that can be run on the CPU or GPU. It is a key foundational library for Deep Learning in Python that you can use directly to create Deep Learning models or wrapper libraries that greatly simplify the process.
Neural Network Libraries is deep learning framework that is intended to be used for research, development, and production. We aim it running everywhere like desktop PCs, HPC clusters, embedded devices and production servers.
You are actually telling Theano to calculate three different functions, where each succeeding function depends on the output of the previously executed function.
In your example, you are using two input parameters: matrix A and matrix B.
A = [[ 1, 1 ],
[ 1, 1 ]]
B = [[ 0, 1 ],
[ 2, 3 ]]
The first output line: [[ 1., 0.], [-1., -2.]]
is calculated by subtracting your A and B matrices:
[[1, 1], - [[0, 1], = [[ 1, 0 ],
[1, 1]] [2, 3]] [-1, -2]
The second output line [[ 1., 0.], [ 1., x2.]]
is merely the absolute value of the difference we just calculated:
abs [[ 1, 0 ], = [[ 1, 0],
[-1, -2]] [ 1, 2]]
The third and final line calculates the squared values, element-wise.
Theano actually interprets your Python code, and infer which variables (or mathematical operations) a given variable depend upon. Thus, if you are only interested in the diff_squared
output, you don't need to include the calls to diff
and abs_diff
too.
f = function([a, b], [diff_squared])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With