Reputation: 47
I was reading over this tensorflow tutorial which specifies how to run a simulation of water ripples using tensorflow. My understanding is that tensorflow variables and placeholders are used in place of generic python variables, but is there any specific (i.e. performance) advantage to using tensorflow over just numpy?
Upvotes: 3
Views: 970
Reputation: 1635
First of all, there are very fundamental differences between libraries like TensorFlow and NumPy. In TensorFlow you basically define a computation graph in a symbolic manner and nothing is computed unless you call the function run
from class Session
. It is very important to be careful about calling the run
function only once (or only if required) so that you avoid redundant computation.
Speaking of performance, libraries like TensorFlow and Theano are good at pruning and optimizing the whole computation graph (before running) and using very optimized kernels to run the operations in the graph on available devices, including GPU. GPU is very fast and useful in doing matrix operations, but NumPy can not take advantage of it. NumPy runs the computation mostly using C++ based code, but unlike TensorFlow it does not apply a graph optimization to the whole computation graph. In fact, there is no such a thing as graph in NumPy. TensorFlow takes the whole computation to a different runtime space and then returns the concrete results after actual execution.
In case you are curious about what exactly is a kernel, the original TensorFlow paper defines it as: "A kernel is a particular implementation of an operation that can be run on a particular type of device (e.g., CPU or GPU)."
There are fairly simple, but good benchmarks at this blog post which show by numbers how much and when TensorFlow is better than NumPy.
To understand how actually TensorFlow works, This post may be useful too.
If your problem is not a big one which needs to deal with large scale matrices and lots of matrix operations, then I would say NumPy is easier to use and you don't need to be worried about performance.
Upvotes: 4