TensorFlow comparison with Numpy
TensorFlow and Numpy are both N-dimensional array libraries. TensorFlow additionally allows us to create tensor functions and compute derivatives. TensorFlow has become one of the major libraries used for deep learning as it is incredibly efficient and can run on GPUs.
The following program describes how TensorFlow
and numpy
can be used to perform similar operations such as creating tensors of a (3,3)
shape:
import TensorFlow as tf import numpy as np tf.InteractiveSession() # TensorFlow operations a = tf.zeros((3,3)) b = tf.ones((3,3)) print(tf.reduce_sum(b, reduction_indices=1).eval()) print(a.get_shape()) # numpy operations a = np.zeros((3, 3)) b = np.ones((3, 3)) print(np.sum(b, axis=1)) print(a.shape)
The output of the preceding code is as follows:
[ 3. 3. 3.] (3, 3) [ 3. 3. 3.] (3, 3)