in Technology by
What is Tensor Data Structure?

1 Answer

0 votes
by

Tensors are used as the basic data structures in TensorFlow language. Tensors represent the connecting edges in any flow diagram called the Data Flow Graph. Tensors are defined as multidimensional array or list.

Tensors are identified by the following three parameters −

Rank

Unit of dimensionality described within tensor is called rank. It identifies the number of dimensions of the tensor. A rank of a tensor can be described as the order or n-dimensions of a tensor defined.

Shape

The number of rows and columns together define the shape of Tensor.

Type

Type describes the data type assigned to Tensor’s elements.

A user needs to consider the following activities for building a Tensor −

  • Build an n-dimensional array
  • Convert the n-dimensional array.

Tensor Data Structure

Various Dimensions of TensorFlow

TensorFlow includes various dimensions. The dimensions are described in brief below −

One dimensional Tensor

One dimensional tensor is a normal array structure which includes one set of values of the same data type.

Declaration

>>> import numpy as np
>>> tensor_1d = np.array([1.3, 1, 4.0, 23.99])
>>> print tensor_1d

The implementation with the output is shown in the screenshot below −

One Dimensional Tensor

The indexing of elements is same as Python lists. The first element starts with index of 0; to print the values through index, all you need to do is mention the index number.

>>> print tensor_1d[0]
1.3
>>> print tensor_1d[2]
4.0

Declaration

Two dimensional Tensors

Sequence of arrays are used for creating “two dimensional tensors”.

The creation of two-dimensional tensors is described below −

Two Dimensional Tensors

Following is the complete syntax for creating two dimensional arrays −

>>> import numpy as np
>>> tensor_2d = np.array([(1,2,3,4),(4,5,6,7),(8,9,10,11),(12,13,14,15)])
>>> print(tensor_2d)
[[ 1 2 3 4]
[ 4 5 6 7]
[ 8 9 10 11]
[12 13 14 15]]
>>>

The specific elements of two dimensional tensors can be tracked with the help of row number and column number specified as index numbers.

>>> tensor_2d[3][2]
14

Two Dimensional Tensors Tracked

Tensor Handling and Manipulations

In this section, we will learn about Tensor Handling and Manipulations.

To begin with, let us consider the following code −

import tensorflow as tf
import numpy as np

matrix1 = np.array([(2,2,2),(2,2,2),(2,2,2)],dtype = 'int32')
matrix2 = np.array([(1,1,1),(1,1,1),(1,<span styl

Related questions

0 votes
    I want to use MLPs to solve regression problem. I have inputs with variable length to fix this I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 1, 2022 in Education by JackTerrance
0 votes
    I'm using TensorFlow Alpha 2.0. I have TFRecords files I'm reading from, each one holding a short ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    Using up-to-date Keras and Tensorflow on Ubuntu 16.04 and 14.04. For the following code: img2D = ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    Suppose I have a Tensorflow tensor. How do I get the dimensions (shape) of the tensor as integer values? I ... 'Dimension' instead. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I am trying to decompose a 3D matrix using python library scikit-tensor. I managed to decompose my Tensor ... the decomposed matrices? Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I am new to TensorFlow. While I am reading the existing documentation, I found the term tensor really confusing. ... types of tensors? Select the correct answer from above options...
asked Jan 29, 2022 in Education by JackTerrance
0 votes
    Which among the following provides support for querying the data structure it stores? (1)Redis (2)MongoDB (3)None of the options (4)CoughDB...
asked Apr 22, 2021 in Technology by JackTerrance
0 votes
    Which of the following is the most widely used external memory data structure? 1) AVL tree 2) B-tree 3) Red-black tree 4) Both AVL tree and Red-black tree...
asked Dec 23, 2020 in Technology by JackTerrance
+1 vote
    Describe dynamic data structure in C programming language?...
asked Nov 8, 2020 in Technology by JackTerrance
+1 vote
    What is the method to save data in a stack data structure type?...
asked Nov 8, 2020 in Technology by JackTerrance
0 votes
    a few days from now I am trying to write a selenium ide test for a data structure tree. I stuck ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    Tm trying to get the difference of 2 sets in linked list Example: Input: Set A: 1 - 2 - 3 ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I have a general problem in the application domain.The data contains a high dimensional feature space with a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    After reading the documentation they recommend not using nested data structure. I am thinking this is the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    As it currently stands, this question is not a good fit for our Q&A format. We expect answers to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
...