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.
Rank | Entity |
0 | Scalar |
1 | Vector |
2 | Matrix |
3 | 3-Tensor |
n | n-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.
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) [[email protected] TENSORFLOW]$
Instructions for updating:
Colocations handled automatically by placer.
2
[[b'Nilesh']
[b'Ritesh']]
Advertisement
