i2tutorials

TensorFlow Tensor

TensorFlow Tensor:

 

Introducing Tensors:

Before going to Tensors, you have some working knowledge on vector calculus and linear algebra and it is a generalization of vectors and matrices for higher dimensionality. Tensors are nothing but the Multidimensional data arrays that can be implemented in Tensorflow. But here we can go deeper to get more Knowledge on tensors and their use in Machine learning.

Plane Vectors:

Theseare the special type of matrices and having the rectangular arrays if numbers. The vectors are ordered collections of numbers and often seen as column matrices. The vectors having one column and a certain number of rows. Another way to understand of plane vector is you also consider vectors as scalar magnitude that has been given a direction.

Remember: an example of a scalar is “6 miles” or “50 min/sec”, while a vector is, for example, “6 miles south” or “50 min/sec west”. The difference between the vector and scalar is that the vector has a direction.

 

You can see in the picture above,vectors have the direction and length. The direction is indicated by the arrow’s head, while the length is indicated by the length of the arrow.

 

Tensors:

Basically, tensors are multilinear maps from vector spaces to the real numbers.(Dual space,vectorspace) and these aretraditionally associated with the discrete mathematics and logic. The machine learning models foundedby the manipulation of tensors and calculations of tensors. The some examples of tensors are

Scalars

Vectors

Matrices

 

The simplest example of tensor is a scalar , a single constant value drawn from the real numbers. Scalar is a 0-tensor, vector is a 1-tensor and matrices are 3-tensor.

 

A tensors is a generalization of vectors and matrices to potentially higher dimensions. Internally, TensorFlow represents tensors as Multi-dimensional and n-dimensional arrays of datatypes.

 

While doing a TensorFlow program, the main object you manipulate and pass around is the tf.Tensor. A tf.Tensor object represents a partially defined computation that will eventually produce a value. TensorFlow programs work by first building a graph of tf.Tensor objects, detailing how each tensor is computed based on the other available tensors and then by running parts of this graph to achieve the desired results.

 

A tf.Tensor has the following properties:

>data type it can be float32 or int32  or string

>shape

And the data type is always known and it must have the same data type. 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.

Some types of tensors are special, and these will be covered in other units of the TensorFlow guide. The main ones are:

Variable

constant

placeholder

SparseTensor

With the exception of tf.Variable, the tensor value is immutable, means the context of a single execution tensors only have a single value. However, evaluating the same tensor twice can return different values; for example that tensor can be the result of generating a random number or reading data from disk.

 

Rank

The rank of a tf.Tensor object is nothing but the its number of dimensions. Rank is nothing but degree or order or n-dimension. Note the rank in tensorflow is not same as the rank of the matrices. the following below table shows, each rank in TensorFlow corresponds to a different mathematical entity:

Rank       Math entity

0Scalar (magnitude only)
mammal = tf.Variable("Elephant", tf.string)
ignition = tf.Variable(451, tf.int16)
floating = tf.Variable(3.14159265359, tf.float64)
its_complicated = tf.Variable(12.3 - 4.85j, tf.complex64)

 

 

1Vector (magnitude and direction)
mystr = tf.Variable(["Hello"], tf.string)

cool_numbers  = tf.Variable([3.14159, 2.71828], tf.float32)

first_primes = tf.Variable([2, 3, 5, 7, 11], tf.int32)

its_very_complicated = tf.Variable([12.3 - 4.85j, 7.5 - 6.23j], tf.complex64)

 

 

Tensorflow 6 (i2tutorials)

 

Matrix (table of numbers)

mymat = tf.Variable([[7],[11]], tf.int16)

myxor = tf.Variable([[False, True],[True, False]], tf.bool)

linear_squares = tf.Variable([[4], [9], [16], [25]], tf.int32)

squarish_squares = tf.Variable([ [4, 9], [16, 25] ], tf.int32)

rank_of_squares = tf.rank(squarish_squares)

mymatC = tf.Variable([[7],[11]], tf.int32)

 

 

nn-Tensor (you get the idea)
my_image = tf.zeros([10, 299, 299, 3])  # batch x height x width x color

 

 

 

 

 

Exit mobile version