Numpy Vs. Tensorflow

Zora Hirbodvash
2 min readFeb 11, 2021

--

Here I am writing about the most interesting differences and similarities between Numpy and TensorFlow. I will update this post as I am learning more about the topics.

Numpy is a linear algebra library for python, and one of the most important and popular libraries in Data Science. TensorFlow is a reimplementation of the Numpy API and can be accessed as tf.experimental.numpy.

Numpy performs a wide variety of numerical computations in Python, and it is the fundamental package for scientific computing. It is generally used for multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays. On the other hand, TensorFlow is an open-source software library for numerical computation using data flow graphs and aims to be a machine learning and deep learning library. However, both Numpy and TensorFlow behave very similar in many aspects ranging from building in the concept of tensor to the fact that they are both array manipulation libraries. From this standpoint, it might be difficult to recognize the exact differences. One of the important ways that TensorFlow augments Numpy is GPU acceleration to support very large concurrency. Although there is CuPy which is a GPU array backend that implements a subset of the NumPy interface, it is not part of the library itself. The other important advantage is that the TensorFlow API performs automatic gradient computation on the arbitrary potential field on tensors. All in all, TensorFlow and NumPy also work reasonably well together. We can obtain the NumPy version from TensorFlow objects. Also, the TensorFlow tensor can be directly converted to a NumPy array in eager mode. TensorFlow reimplements a large portion of NumPy API. Most NumPy API have TensorFlow equivalence. But there are three differences. First, TensorFlow renamed a few functions: np.concatenate → tf.concat. Second, TensorFlow uses function call convention over methods. Example:

NumPy: x.reshape(3,1)

TensorFlow: tf.reshape(x, (3,1))

Last but not least, TensorFlow is sensitive highly about datatypes used. They cannot be implicitly mixed.

--

--

Zora Hirbodvash
Zora Hirbodvash

Written by Zora Hirbodvash

I am physicist, and I am working as data scientist now

No responses yet