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])
Tensorflow can't do much magic to be better (while guaranteeing same accuracy). Tensorflow is consistently much slower than Numpy in my tests.
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.
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.
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.
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.
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:
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.
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:
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.
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
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