

{"id":107439,"date":"2022-12-28T09:00:35","date_gmt":"2022-12-28T03:30:35","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=107439"},"modified":"2022-12-28T14:27:38","modified_gmt":"2022-12-28T08:57:38","slug":"tensors-in-pytorch","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/tensors-in-pytorch\/","title":{"rendered":"Tensors in PyTorch"},"content":{"rendered":"<p>Tensor is the data-type in which all the deep learning models using pytorch are built. They are just like numpy arrays with the added advantage that they can be loaded on a GPU. The first step of building any machine learning model is the preprocessing of the data which always involves converting the available data into tensors if they are in some other format.<\/p>\n<h3>Creating Tensors using PyTorch<\/h3>\n<p>Using PyTorch, we can create tensors and if a dataset is available we can convert it into tensors too.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import torch<\/pre>\n<p>Analogous to numpy, we can create an empty tensor, tensor with all elements 0 or 1 and tensors having random numbers.<\/p>\n<p><strong>a. Creating an empty Tensor in Pytorch:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">a=torch.empty((2,3,4))<\/pre>\n<p><strong>b. Creating a tensor with all elements equal to 0<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">b=torch.zeros(3,4)<\/pre>\n<p><strong>c. Creating a tensor with all elements equal to1<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">c=torch.ones(3,2,4)\r\nprint(a)\r\nprint(b)\r\nprint(c)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p><span style=\"font-weight: 400\">tensor([[[9.1837e-39, 4.6837e-39, 9.2755e-39, 1.0837e-38],<\/span><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0[8.4490e-39, 6.9796e-39, 9.5510e-39, 1.0010e-38],<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0[1.0929e-38, 1.0469e-38, 1.0561e-38, 9.9184e-39]],<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0[[9.0000e-39, 1.0561e-38, 1.0653e-38, 4.1327e-39],<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0[8.9082e-39, 9.8265e-39, 9.4592e-39, 1.0561e-38],<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0[1.0653e-38, 1.0469e-38, 9.5510e-39, 1.0745e-38]]])<\/span><\/p>\n<p><span style=\"font-weight: 400\">tensor([[0., 0., 0., 0.],<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0[0., 0., 0., 0.],<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0[0., 0., 0., 0.]])<\/span><\/p>\n<p><span style=\"font-weight: 400\">tensor([[[1., 1., 1., 1.],<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0[1., 1., 1., 1.]],<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0[[1., 1., 1., 1.],<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0[1., 1., 1., 1.]],<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0[[1., 1., 1., 1.],<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0[1., 1., 1., 1.]]])<\/span><\/p>\n<\/div>\n<p>We can also create a tensor with 1 occupying all the diagonal positions the non diagonal elements being 0<\/p>\n<p><strong>d. Creating a tensor with diagonal elements equal to 1.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">d=torch.eye(3)\r\nprint(d)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p><span style=\"font-weight: 400\">tensor([[1., 0., 0.],<\/span><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0[0., 1., 0.],<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0[0., 0., 1.]])<\/span><\/p>\n<\/div>\n<p>We will use the MNIST dataset which is available with t pytorch to see how we can convert a dataframe into tensor from any other format.<\/p>\n<p>To do so we will import additional libraries.<\/p>\n<p><strong>e. Converting a dataset into a tensor<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import torchvision\r\nfrom torchvision import transforms,datasets<\/pre>\n<p>Torch vision has to be installed before being imported. Run the command &#8220;pip install torchvision&#8221; on the terminal or anaconda prompt and it will get installed in a few minutes.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">train=datasets.MNIST(\"\", train=True,download=True,transform=transforms.Compose([transforms.ToTensor()]))\r\ntest=datasets.MNIST(\"\", train=False,download=True,transform=transforms.Compose([transforms.ToTensor()]))<\/pre>\n<p>In the above code we have downloaded the MNIST dataset and transformed it into tensor.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">train<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p><span style=\"font-weight: 400\">Dataset MNIST<\/span><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0Number of datapoints: 60000<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0Root location:\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0Split: Train<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0StandardTransform<\/span><\/p>\n<p><span style=\"font-weight: 400\">Transform: Compose(<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ToTensor()<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0)<\/span><\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">test<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p><span style=\"font-weight: 400\">Dataset MNIST<\/span><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0Number of datapoints: 10000<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0Root location:\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0Split: Test<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0StandardTransform<\/span><\/p>\n<p><span style=\"font-weight: 400\">Transform: Compose(<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ToTensor()<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0)<\/span><\/p>\n<\/div>\n<p><strong>f. Converting NumPy arrays into tensors.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import numpy as np\r\narr=np.array([1,2,3])#We\u00a0have\u00a0created\u00a0a\u00a0numpy\u00a0array\u00a0which\u00a0we\u00a0will\u00a0convert\u00a0into\u00a0tensor.\r\narr<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\"><span style=\"font-weight: 400\">array([1, 2, 3])<\/span><\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">torch.from_numpy(arr)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\"><span style=\"font-weight: 400\">tensor([1, 2, 3], dtype=torch.int32)<\/span><\/div>\n<p>The numpy array has been converted into a tensor.<\/p>\n<h3>PyTorch Tensor Operations<\/h3>\n<p>Just like numpy, we can perform many operations such as addition, subtraction, multiplication, exponentiation of two tensors using PyTorch.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">t1=torch.ones(4,4)\r\nt2=torch.eye(4)\r\nt1<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p><span style=\"font-weight: 400\">tensor([[1., 1., 1., 1.],<\/span><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 [1., 1., 1., 1.],<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 [1., 1., 1., 1.],<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 [1., 1., 1., 1.]])<\/span><\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">t2<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p><span style=\"font-weight: 400\">tensor([[1., 0., 0., 0.],<\/span><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0[0., 1., 0., 0.],<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0[0., 0., 1., 0.],<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0[0., 0., 0., 1.]])<\/span><\/p>\n<\/div>\n<p><strong>a. Tensor Addition<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">t1+t2<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p><span style=\"font-weight: 400\">tensor([[2., 1., 1., 1.],<\/span><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 [1., 2., 1., 1.],<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 [1., 1., 2., 1.],<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 [1., 1., 1., 2.]])<\/span><\/p>\n<\/div>\n<p><strong>b. Tensor Multiplication<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">t1*t2<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p><span style=\"font-weight: 400\">tensor([[1., 0., 0., 0.],<\/span><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0[0., 1., 0., 0.],<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0[0., 0., 1., 0.],<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0[0., 0., 0., 1.]])<\/span><\/p>\n<\/div>\n<p><strong>c. Tensor Subtraction<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">t1-t2<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p><span style=\"font-weight: 400\">tensor([[0., 1., 1., 1.],<\/span><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0[1., 0., 1., 1.],<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0[1., 1., 0., 1.],<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0[1., 1., 1., 0.]])<\/span><\/p>\n<\/div>\n<p><strong>d. Tensor Exponentiation<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">t1**t2<\/pre>\n<p><strong>e. Scalar multiple of a Tensor<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">2*t1<\/pre>\n<p><strong>f. Resizing a tensor<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">a<\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">a.shape<\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">a.resize(2,12)<\/pre>\n<h3>Summary<\/h3>\n<p>Tensors are a data structure just like numpy. All the operations on tensors that we require for training our model can easily be done using the different PyTorch methods as we have seen above. Due to the fact that tensors of multiple dimensions can be built, the training process can be made easier by increasing the dimensions of the dataset which is very effective especially in classification models.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tensor is the data-type in which all the deep learning models using pytorch are built. They are just like numpy arrays with the added advantage that they can be loaded on a GPU. The&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":111251,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26498],"tags":[27174],"class_list":["post-107439","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-pytorch-tutorials","tag-tensors-in-pytorch"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Tensors in PyTorch - DataFlair<\/title>\n<meta name=\"description\" content=\"Tensors are a data structure like numpy. All operations on tensors that we require for training our model can be done using PyTorch methods.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/tensors-in-pytorch\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Tensors in PyTorch - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Tensors are a data structure like numpy. All operations on tensors that we require for training our model can be done using PyTorch methods.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/tensors-in-pytorch\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-12-28T03:30:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-12-28T08:57:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/12\/pytorch-tensors.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Tensors in PyTorch - DataFlair","description":"Tensors are a data structure like numpy. All operations on tensors that we require for training our model can be done using PyTorch methods.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/tensors-in-pytorch\/","og_locale":"en_US","og_type":"article","og_title":"Tensors in PyTorch - DataFlair","og_description":"Tensors are a data structure like numpy. All operations on tensors that we require for training our model can be done using PyTorch methods.","og_url":"https:\/\/data-flair.training\/blogs\/tensors-in-pytorch\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2022-12-28T03:30:35+00:00","article_modified_time":"2022-12-28T08:57:38+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/12\/pytorch-tensors.webp","type":"image\/webp"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/tensors-in-pytorch\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/tensors-in-pytorch\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Tensors in PyTorch","datePublished":"2022-12-28T03:30:35+00:00","dateModified":"2022-12-28T08:57:38+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/tensors-in-pytorch\/"},"wordCount":449,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/tensors-in-pytorch\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/12\/pytorch-tensors.webp","keywords":["Tensors in PyTorch"],"articleSection":["PyTorch Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/tensors-in-pytorch\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/tensors-in-pytorch\/","url":"https:\/\/data-flair.training\/blogs\/tensors-in-pytorch\/","name":"Tensors in PyTorch - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/tensors-in-pytorch\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/tensors-in-pytorch\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/12\/pytorch-tensors.webp","datePublished":"2022-12-28T03:30:35+00:00","dateModified":"2022-12-28T08:57:38+00:00","description":"Tensors are a data structure like numpy. All operations on tensors that we require for training our model can be done using PyTorch methods.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/tensors-in-pytorch\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/tensors-in-pytorch\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/tensors-in-pytorch\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/12\/pytorch-tensors.webp","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2022\/12\/pytorch-tensors.webp","width":1200,"height":628,"caption":"pytorch tensors"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/tensors-in-pytorch\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"PyTorch Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/pytorch-tutorials\/"},{"@type":"ListItem","position":3,"name":"Tensors in PyTorch"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/107439","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=107439"}],"version-history":[{"count":6,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/107439\/revisions"}],"predecessor-version":[{"id":111254,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/107439\/revisions\/111254"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/111251"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=107439"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=107439"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=107439"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}