Tensors: The building block of TensorFlow

0
947
Photo source: https://en.wikipedia.org/wiki/TensorFlow

TensorFlow uses tensor to define the framework and processing data. A tensor conceptualized multidimensions vectors and matrices. Mathematically, a tensor is a geometric object that maps in a multi-linear manner geometric vectors, scalars, and another tensor(s) to a resulting tensor.

RankEntity
0Scalar
1Vector
2Matrix
33-Tensor
nn-Tensor

These tensor objects used to implement a Graph object which coordinated among them self to produce the desired result. A tensor(tf.Tensor) object has the two basic properties that are “Data Type” and “Shape”. Each element in the Tensor has the same data type, and the data type is always known. The shape (that is, the number of dimensions it has and the size of each dimension) might be only partially known. Most operations produce tensors of fully-known shapes if the shapes of their inputs are also fully known, but in some cases, it’s only possible to find the shape of a tensor at graph execution time. Apart from this are other possible variables are also there.

-Advertisement-

Tensor Rank (dimension)

Rank of tensor is the actual dimension of the database. The tensor shape represents the size of each dimension. A 0 rank means zero dimension and represents scalar quantity.

fruit = tf.Variable("Apple", tf.string)
Count = tf.Variable(100, tf.int16)
Weight = tf.Variable(3.14159265359, tf.float64)

Rank 1 means One dimension that is a list of items.

Names = tf.Variable(["Nilesh","Akash","Ritesh"], tf.string) 
Weights  = tf.Variable([100, 110], tf.float32)
GPA = tf.Variable([4,3], tf.int32)

Rank 2 means 2D array that is List of List.

Students = tf.Variable([["Nilesh"],["Ritesh"]], tf.string)
Ages = tf.Variable([[25],[26]], tf.int16)
Tall = tf.Variable([[False], [True]], tf.bool)

 Rank of atf.Tensor object

tf.rank method can be use to determine rank of a object.

r = tf.rank(Students)
# After the graph runs, r will hold the value 2.

Example:

 import tensorflow as tf
sess = tf.InteractiveSession()
Students = tf.Variable([["Nilesh"],["Ritesh"]], tf.string)
r = tf.rank(Students)
init = tf.global_variables_initializer()
with sess.as_default():
print_op = tf.print(r)
with tf.control_dependencies([print_op]):
out = tf.add(r, r)
sess.run(out)
with sess.as_default():
sess.run(init)
v = sess.run(Students)
print(v)
(venv) [nilesh@localhost TENSORFLOW]$ 
Instructions for updating:
Colocations handled automatically by placer.
2
[[b'Nilesh']
[b'Ritesh']]

Previous articleInspiring Talk with an Eleven Year Old Coder and his Brothers
Next articleCan AI Ease Your Manager’s Burden?
Nilesh Kumar
I am Nilesh Kumar, a graduate student at the Department of Biology, UAB under the mentorship of Dr. Shahid Mukhtar. I joined UAB in Spring 2018 and working on Network Biology. My research interests are Network modeling, Mathematical modeling, Game theory, Artificial Intelligence and their application in Systems Biology. I graduated with master’s degree “Master of Technology, Information Technology (Specialization in Bioinformatics)” in 2015 from Indian Institute of Information Technology Allahabad, India with GATE scholarship. My Master’s thesis was entitled “Mirtron Prediction through machine learning approach”. I worked as a research fellow at The International Centre for Genetic Engineering and Biotechnology, New Delhi for two years.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.