Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Numpy and Tensorflow? [closed]

is numpy and tensorflow the same thing?? I just started learning programming..this i completely unrelated to my course.. I was learning AI and found tensorflow... I started to look videos and I saw the code below:

import tensorflow as tf

tf.ones([1,2,3])

tf.zeros([2,3,2])
import numpy as np

np.zeros([2,3,2])

np.ones([1,2,3])
like image 358
Bijay Karki Avatar asked Apr 20 '20 09:04

Bijay Karki


People also ask

Is NumPy faster than TensorFlow?

Tensorflow can't do much magic to be better (while guaranteeing same accuracy). Tensorflow is consistently much slower than Numpy in my tests.

Is TensorFlow built on NumPy?

TensorFlow implements a subset of the NumPy API, available as tf. experimental. numpy . This allows running NumPy code, accelerated by TensorFlow, while also allowing access to all of TensorFlow's APIs.

Do you need NumPy for TensorFlow?

TensorFlow is a reimplementation of the Numpy API and can be accessed as tf. experimental. numpy . Last but not least, TensorFlow is sensitive highly about datatypes used.

What is the difference between Python and TensorFlow?

Nodes and tensors in TensorFlow are Python objects, and TensorFlow applications are themselves Python applications. The actual math operations, however, are not performed in Python. The libraries of transformations that are available through TensorFlow are written as high-performance C++ binaries.

Is it possible to create a tensor function in NumPy?

Tensors are multilinear maps from Vector spaces to real numbers. Scalar, Vector and Matrix are all tensors. So a tensor could be represented as a multi-dimensional array. Numpy has N-d array support but does not have methods to create tensor functions, can’t automatically compute derivatives and it can’t take advantage of GPU.

What is a tensor in TensorFlow?

When you use TensorFlow, the data must be loaded into a special data type called a Tensor. Tensors mirror NumPy arrays in more ways than they are dissimilar. After the tensors are created from the training data, the graph of computations is defined:

Is Python or TensorFlow better for large batch arrays?

While Python is a robust general-purpose programming language, its libraries targeted towards numerical computation will win out any day when it comes to large batch operations on arrays. While the NumPy example proved quicker by a hair than TensorFlow in this case, it’s important to note that TensorFlow really shines for more complex cases.

How do NumPy tensor arrays mirror NumPy arrays?

Tensors mirror NumPy arrays in more ways than they are dissimilar. After the tensors are created from the training data, the graph of computations is defined:


Video Answer


1 Answers

I think it may be worth adding a bit more of information, although it is easy to find about it just searching around a bit.

NumPy and TensorFlow are actually very similar in many respects. Both are, essentially, array manipulation libraries, built around the concept of tensors (or nd-arrays, in NumPy terms). Originally, in TensorFlow 0.x and 1.x, there was only "graph mode", with all values being "symbolic tensors" that did not have a specific value until one was fed at a later point... It was a bit confusing and quite different from NumPy. Nowadays "graph mode" still exists but, for the most part, TensorFlow 2.x works in "eager mode", where each tensor has a specific value. This makes it more similar to NumPy, so the differences may seem subtle. So maybe we can draft a list with some of the most significant points.

  • NumPy was developed as a full-fledged open source tensor algebra package for Python that could rival MATLAB and the likes. It is a Python library with a long history and plenty of functionality, either directly in it or built around it (see SciPy and different scikits). TensorFlow was developed by Google much more recently specifically for the purpose of building machine learning models (although you could use it for many other tasks), continuing the ideas from the (now discontinued) Theano library. Although TensorFlow is most commonly used with Python, it can be used in C/C++ and other languages too, which is important because it allows you to train a model in Python and then integrate it in an existing application written in another language.
  • A main selling point of TensorFlow is that it can automatically differentiate computations. This is an essential feature for deep learning, that uses gradient-based optimization (backpropagation), and it means that you can pretty much just write whatever you want to compute and TensorFlow will figure out the gradients by itself. There are things like Autograd or JAX for NumPy, but they are not as powerful as TensorFlow automatic differentiation, which actually maintains a computation graph structure under the hood (the name "TensorFlow" refers to the tensors and their gradients "flowing" through the computation graph).
  • TensorFlow offers GPU computation with CUDA out of the box. Again there are things like CuPy for NumPy, but it is not part of the library itself.
  • TensorFlow integrates a lot more functionality that is not strictly array manipulation into the library itself, like image manipulation and common neural network utilities. NumPy tends to defer that kind of things to additional libraries like SciPy, making it more of an ecosystem and less monolithic. TensorFlow has some of that too, like TensorFlow Probability or TensorFlow Graphics, but it is not too developed yet.
  • TensorFlow offers a bunch of useful stuff if you are doing machine learning, like training checkpoints, distributed training, TensorBoard, TensorFlow Serving, etc. It also integrates better (or at all) with inference platforms and standards like TensorRT, Google Coral, ONNX and that kind of stuff.
  • NumPy generally integrates better with the "traditional" Python scientific stack, like Jupyter, Matplotlib, Pandas, dask, xarray, etc. There are pretty good libraries to do machine learning with NumPy too, like scikit-learn or Chainer, which are perfectly good if you only need to work in Python.
  • TensorFlow and NumPy also work reasonably well together, specially in eager mode, where any TensorFlow tensor can be directly converted to a NumPy array.

In general, if you are not going to work on machine learning, and specifically neural networks / deep learning, NumPy is probably the best choice, as it is easier to pick up, at least for general purposes, and has a larger community and corpus of documentation and resources. However, if you are going to be doing a significant amount work on that area, it may be worth to give TensorFlow a shot

like image 134
jdehesa Avatar answered Oct 22 '22 10:10

jdehesa