{"id":53893,"date":"2025-09-18T10:42:38","date_gmt":"2025-09-18T00:42:38","guid":{"rendered":"https:\/\/www.cloudproinc.com.au\/?p=53893"},"modified":"2025-09-18T10:42:41","modified_gmt":"2025-09-18T00:42:41","slug":"get-started-with-tensors-with-pytorch","status":"publish","type":"post","link":"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/18\/get-started-with-tensors-with-pytorch\/","title":{"rendered":"Get Started With Tensors With PyTorch"},"content":{"rendered":"\n<p>In this blog post Get Started With Tensors with PyTorch we will walk through how to work with tensors with simple, copy\u2011paste examples you can use today.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>Tensors are the workhorse behind modern AI and numerical computing. Think of them as powerful, N\u2011dimensional arrays that can live on CPUs or GPUs and support fast math, automatic differentiation, and clean syntax. In this article, we start with a high-level explanation, then move step by step through creating a tensor, indexing it, adding values, and performing common operations you\u2019ll use in real projects.<\/p>\n\n\n\n<p>We\u2019ll use PyTorch because it\u2019s concise, production\u2011ready, and maps naturally to how engineers think about data. The same ideas apply across frameworks (NumPy, TensorFlow, JAX), but PyTorch keeps the examples clean.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-s-a-tensor-and-why-it-matters\">What\u2019s a tensor and why it matters<\/h2>\n\n\n\n<p>A tensor generalizes familiar objects:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>0-D: scalar (e.g., 3.14)<\/li>\n\n\n\n<li>1-D: vector (e.g., [1, 2, 3])<\/li>\n\n\n\n<li>2-D: matrix (e.g., a spreadsheet)<\/li>\n\n\n\n<li>3-D and beyond: stacks of matrices, images, batches, sequences<\/li>\n<\/ul>\n\n\n\n<p>Under the hood, a <a href=\"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/18\/the-autonomy-of-tensors\/\">tensor <\/a>is a block of memory plus metadata: shape (dimensions), dtype (precision), device (CPU or GPU), and sometimes a gradient buffer. Operations call into highly optimized libraries (BLAS, cuBLAS, cuDNN) so the same Python code can run fast on GPU. Autograd (reverse\u2011mode automatic differentiation) keeps track of operations so you can compute gradients for optimization and training.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-setup\">Setup<\/h2>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-3fff797458fde48527c5cac158e620b2\"><code># Install if needed (in a fresh environment recommended)\n# pip install torch --index-url https:\/\/download.pytorch.org\/whl\/cpu\n# or follow official instructions for CUDA builds\n\nimport torch\n\n# Optional: pick a device\ndevice = 'cuda' if torch.cuda.is_available() else 'cpu'\nprint('Using device:', device)\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-create-tensors\">Create tensors<\/h2>\n\n\n\n<p>You can create tensors from Python lists, NumPy arrays, or with factory functions.<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-44892637b635dc6d75fbed20fb7bbf08\"><code>import torch\n\n# From Python data\nx = torch.tensor(&#91;1, 2, 3], dtype=torch.float32)\nM = torch.tensor(&#91;&#91;1, 2], &#91;3, 4]], dtype=torch.int64)\n\n# Factory functions\nzeros = torch.zeros((2, 3))            # 2x3 of zeros, float32 by default\nones = torch.ones_like(zeros)          # same shape as zeros, filled with ones\narng = torch.arange(0, 10, 2)          # 0,2,4,6,8\nrandn = torch.randn(3, 4)              # standard normal\n\n# Dtype and device\nfp16 = torch.randn(2, 2, dtype=torch.float16, device=device)\n\nprint(x.dtype, x.shape, x.device)\n<\/code><\/pre>\n\n\n\n<p>Tip: use arange for integer steps and linspace for evenly spaced points in a range.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-indexing-and-slicing\">Indexing and slicing<\/h2>\n\n\n\n<p>Torch indexing feels like NumPy: square brackets, slices, masks, and advanced indexing.<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-d8de18f0630e135faecf6537616d41da\"><code>v = torch.tensor(&#91;10, 20, 30, 40, 50])\nprint(v&#91;0])           # 10\nprint(v&#91;-1])          # 50\nprint(v&#91;1:4])         # &#91;20, 30, 40]\n\nA = torch.arange(1, 13).reshape(3, 4)  # &#91;&#91;1..4],&#91;5..8],&#91;9..12]]\nprint(A&#91;0, 0])        # top-left\nprint(A&#91;:, 0])        # first column\nprint(A&#91;1:, 2:])      # bottom-right 2x2 block\n\n# Boolean mask\nmask = A % 2 == 0\nprint(A&#91;mask])        # all even numbers\n\n# Advanced indexing with a list of indices\nrows = torch.tensor(&#91;0, 2])\ncols = torch.tensor(&#91;1, 3])\nprint(A&#91;rows, cols])  # elements at (0,1) and (2,3)\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-adding-values-and-common-math\">Adding values and common math<\/h2>\n\n\n\n<p>PyTorch supports element\u2011wise ops, broadcasting, and linear algebra. Out\u2011of\u2011place operations return new tensors; in\u2011place operations modify existing tensors (ending with an underscore, like <code>add_<\/code>).<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-5328991420e934e51b571634ce1697ce\"><code>x = torch.tensor(&#91;1.0, 2.0, 3.0])\n\n# Element-wise\nprint(x + 10)         # &#91;11, 12, 13]\nprint(x * 2)          # &#91;2, 4, 6]\n\n# In-place (modifies x)\nx.add_(5)             # x becomes &#91;6, 7, 8]\n\n# Broadcasting: shapes auto-expand when compatible\nB = torch.ones((3, 4))\nbias = torch.tensor(&#91;1.0, 2.0, 3.0, 4.0])\nprint(B + bias)       # bias added to each row\n\n# Reductions\nprint(B.sum())        # scalar sum\nprint(B.mean(dim=0))  # column-wise mean -&gt; shape (4,)\nprint(B.max(dim=1))   # per-row max + indices\n\n# Linear algebra\nA = torch.randn(2, 3)\nW = torch.randn(3, 4)\nY = A @ W             # matrix multiply (2x4)\n\nu = torch.randn(4)\nv = torch.randn(4)\nprint(torch.dot(u, v))  # dot product\n<\/code><\/pre>\n\n\n\n<p>Broadcasting rules: trailing dimensions must match or be 1; PyTorch virtually \u201cstretches\u201d size\u20111 dimensions without copying data. If the shapes don\u2019t align, you\u2019ll get a runtime error\u2014check shapes with <code>.shape<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-working-with-shapes\">Working with shapes<\/h2>\n\n\n\n<p>Reshaping is the glue for real workloads. You\u2019ll stack batches, flatten features, reorder channels, and add singleton dimensions.<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-e529ed47945474bf91ba1e24d5cd1526\"><code>T = torch.arange(24).reshape(2, 3, 4)  # (batch=2, rows=3, cols=4)\n\n# Reshape\/flatten\nflat = T.reshape(2, -1)   # infer last dim -&gt; (2, 12)\n\n# Transpose\/permute\nT_tr = T.transpose(1, 2)  # swap dims 1 and 2 -&gt; (2, 4, 3)\nT_perm = T.permute(2, 0, 1)  # reorder arbitrarily -&gt; (4, 2, 3)\n\n# Add\/remove singleton dims\nx = torch.tensor(&#91;1, 2, 3])           # (3,)\nxu = x.unsqueeze(0)                   # (1, 3)\nxs = xu.squeeze(0)                    # back to (3,)\n\n# Concatenate and stack\nA = torch.ones(2, 3)\nB = torch.zeros(2, 3)\ncat_rows = torch.cat(&#91;A, B], dim=0)   # (4, 3)\nstack_newdim = torch.stack(&#91;A, B], dim=0)  # (2, 2, 3)\n<\/code><\/pre>\n\n\n\n<p>Use <code>reshape<\/code> for a safe reshape (it handles non\u2011contiguous memory by copying if needed). <code>view<\/code> is faster but requires contiguous tensors.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-device-management-and-moving-data\">Device management and moving data<\/h2>\n\n\n\n<p>Switching between CPU and GPU is explicit and simple.<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-c22b7afc1839f440c9594c3274bcb755\"><code># Create on CPU, move to GPU if available\nx = torch.randn(1024, 1024)\nx = x.to(device)\n\n# Bring back to CPU (e.g., to convert to NumPy)\nxcpu = x.to('cpu')\n<\/code><\/pre>\n\n\n\n<p>Moving large tensors between CPU and GPU is relatively expensive. Keep tensors on the device where the bulk of computation happens.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-numpy-interoperability\">NumPy interoperability<\/h2>\n\n\n\n<p>PyTorch and NumPy can share memory (zero\u2011copy) on CPU.<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-9d37443b89d8cfb7ae1137ef09d8e2f5\"><code>import numpy as np\n\n# NumPy -&gt; Torch (shares memory)\na_np = np.array(&#91;1, 2, 3], dtype=np.float32)\na_t = torch.from_numpy(a_np)        # CPU only\n\n# Change in one reflects in the other\na_np&#91;0] = 99\nprint(a_t)  # tensor(&#91;99.,  2.,  3.])\n\n# Torch -&gt; NumPy\nb_t = torch.tensor(&#91;4.0, 5.0, 6.0])\nb_np = b_t.numpy()                  # requires CPU tensor\n\n# If tensor requires grad, detach first\nw = torch.tensor(&#91;1.0, 2.0, 3.0], requires_grad=True)\nwnp = w.detach().cpu().numpy()\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-autograd-in-one-minute\">Autograd in one minute<\/h2>\n\n\n\n<p>Autograd builds a computation graph as you operate on tensors with <code>requires_grad=True<\/code>. Calling <code>backward()<\/code> computes gradients with respect to those tensors.<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-d0ffc98c53adaca7a8c71d68938845f8\"><code>w = torch.tensor(&#91;2.0, -1.0, 0.5], requires_grad=True)\nloss = (w**2).sum()   # simple quadratic: 4 + 1 + 0.25 = 5.25\nloss.backward()\nprint(w.grad)         # gradient is 2*w -&gt; &#91;4.0, -2.0, 1.0]\n\n# Zero gradients between steps in optimization loops\nw.grad.zero_()\n<\/code><\/pre>\n\n\n\n<p>Note: avoid in\u2011place ops on tensors that require grad if those ops are part of the computation graph; they can invalidate history. When in doubt, use out\u2011of\u2011place operations or <code>.clone()<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-mini-workflow-example\">Mini workflow example<\/h2>\n\n\n\n<p>Let\u2019s put it together: normalize a batch, apply a linear layer, and compute a simple loss.<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-4c008e9a28250254b731adcc3f11d200\"><code>torch.manual_seed(0)\n\n# Fake batch: 32 samples, 10 features\nX = torch.randn(32, 10, device=device)\n\n# Normalize per-feature: (X - mean) \/ std\nmean = X.mean(dim=0, keepdim=True)\nstd = X.std(dim=0, unbiased=False, keepdim=True)\nXn = (X - mean) \/ (std + 1e-6)\n\n# Linear layer: Y = Xn @ W + b\nW = torch.randn(10, 3, device=device, requires_grad=True)\nb = torch.zeros(3, device=device, requires_grad=True)\nY = Xn @ W + b  # (32, 3)\n\n# Target scores (pretend regression)\ntarget = torch.randn(32, 3, device=device)\nloss = ((Y - target) ** 2).mean()  # MSE\n\nloss.backward()  # compute gradients w.r.t. W and b\nprint('Loss:', float(loss))\nprint('Grad norm W:', W.grad.norm().item())\nprint('Grad norm b:', b.grad.norm().item())\n<\/code><\/pre>\n\n\n\n<p>This snippet demonstrates common patterns: reductions, broadcasting, matrix multiplies, and autograd across CPU\/GPU seamlessly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-cheat-sheet\">Cheat sheet<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create: <code>torch.tensor<\/code>, <code>zeros<\/code>, <code>ones<\/code>, <code>arange<\/code>, <code>randn<\/code><\/li>\n\n\n\n<li>Inspect: <code>.shape<\/code>, <code>.dtype<\/code>, <code>.device<\/code><\/li>\n\n\n\n<li>Index: <code>t[i]<\/code>, <code>t[i:j]<\/code>, masks, advanced indexing<\/li>\n\n\n\n<li>Math: element\u2011wise ops, reductions (<code>sum<\/code>, <code>mean<\/code>, <code>max<\/code>), <code>@<\/code> for matmul<\/li>\n\n\n\n<li>Shapes: <code>reshape<\/code>, <code>permute<\/code>, <code>unsqueeze<\/code>\/<code>squeeze<\/code>, <code>cat<\/code>, <code>stack<\/code><\/li>\n\n\n\n<li>Device: <code>.to('cuda')<\/code> \/ <code>.to('cpu')<\/code><\/li>\n\n\n\n<li>Autograd: set <code>requires_grad=True<\/code>, call <code>backward()<\/code><\/li>\n\n\n\n<li>I\/O: <code>from_numpy<\/code> and <code>.numpy()<\/code> (CPU tensors)<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-wrap-up\">Wrap up<\/h2>\n\n\n\n<p>Tensors turn math into scalable, production\u2011ready code. You learned how to create, index, add, reshape, and compute with tensors; how broadcasting and reductions work; and how to use devices and autograd. With these building blocks, you can handle everything from feature engineering to deep learning training loops efficiently.<\/p>\n\n\n\n<p>Next step: paste the snippets into a notebook or script, swap in your own data shapes, and build from there. When you\u2019re ready to scale up, keep your tensors on the right device and let PyTorch\u2019s kernels do the heavy lifting.<\/p>\n\n\n\n<ul class=\"wp-block-yoast-seo-related-links yoast-seo-related-links\">\n<li><a href=\"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/08\/27\/what-are-tensors-in-ai-and-large-language-models-llms\/\">What Are Tensors in AI and Large Language Models (LLMs)?<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/18\/the-autonomy-of-tensors\/\">The Autonomy of Tensors<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/07\/21\/running-pytorch-in-microsoft-azure-machine-learning\/\">Running PyTorch in Microsoft Azure Machine Learning<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/15\/loading-and-saving-pytorch-weights\/\">Loading and Saving PyTorch Weights<\/a><\/li>\n\n\n\n<li><a href=\"null\">Updating Microsoft Edge Using Intune<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>A clear, hands-on walkthrough of tensors in PyTorch. Learn creation, indexing, math, shapes, and GPU basics with concise examples you can copy-paste.<\/p>\n","protected":false},"author":1,"featured_media":53894,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_yoast_wpseo_focuskw":"Get Started With Tensors With PyTorch","_yoast_wpseo_title":"","_yoast_wpseo_metadesc":"Learn to get started with tensors with PyTorch. Master tensor creation and operations with easy examples for real projects.","_yoast_wpseo_opengraph-title":"","_yoast_wpseo_opengraph-description":"","_yoast_wpseo_twitter-title":"","_yoast_wpseo_twitter-description":"","_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[24,13,75],"tags":[],"class_list":["post-53893","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai","category-blog","category-pytorch"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Get Started With Tensors With PyTorch - CPI Consulting<\/title>\n<meta name=\"description\" content=\"Learn to get started with tensors with PyTorch. Master tensor creation and operations with easy examples for real projects.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/18\/get-started-with-tensors-with-pytorch\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Get Started With Tensors With PyTorch\" \/>\n<meta property=\"og:description\" content=\"Learn to get started with tensors with PyTorch. Master tensor creation and operations with easy examples for real projects.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/18\/get-started-with-tensors-with-pytorch\/\" \/>\n<meta property=\"og:site_name\" content=\"CPI Consulting\" \/>\n<meta property=\"article:published_time\" content=\"2025-09-18T00:42:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-09-18T00:42:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cloudproinc.com.au\/wp-content\/uploads\/2025\/09\/tensors-made-practical-for-engineers-and-data-teams-with-pytorch-1024x683.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"683\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"CPI Staff\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"CPI Staff\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/18\\\/get-started-with-tensors-with-pytorch\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/18\\\/get-started-with-tensors-with-pytorch\\\/\"},\"author\":{\"name\":\"CPI Staff\",\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/#\\\/schema\\\/person\\\/192eeeb0ce91062126ce3822ae88fe6e\"},\"headline\":\"Get Started With Tensors With PyTorch\",\"datePublished\":\"2025-09-18T00:42:38+00:00\",\"dateModified\":\"2025-09-18T00:42:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/18\\\/get-started-with-tensors-with-pytorch\\\/\"},\"wordCount\":670,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/18\\\/get-started-with-tensors-with-pytorch\\\/#primaryimage\"},\"thumbnailUrl\":\"\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/tensors-made-practical-for-engineers-and-data-teams-with-pytorch.png\",\"articleSection\":[\"AI\",\"Blog\",\"PyTorch\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/18\\\/get-started-with-tensors-with-pytorch\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/18\\\/get-started-with-tensors-with-pytorch\\\/\",\"url\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/18\\\/get-started-with-tensors-with-pytorch\\\/\",\"name\":\"Get Started With Tensors With PyTorch - CPI Consulting\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/18\\\/get-started-with-tensors-with-pytorch\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/18\\\/get-started-with-tensors-with-pytorch\\\/#primaryimage\"},\"thumbnailUrl\":\"\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/tensors-made-practical-for-engineers-and-data-teams-with-pytorch.png\",\"datePublished\":\"2025-09-18T00:42:38+00:00\",\"dateModified\":\"2025-09-18T00:42:41+00:00\",\"description\":\"Learn to get started with tensors with PyTorch. Master tensor creation and operations with easy examples for real projects.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/18\\\/get-started-with-tensors-with-pytorch\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/18\\\/get-started-with-tensors-with-pytorch\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/18\\\/get-started-with-tensors-with-pytorch\\\/#primaryimage\",\"url\":\"\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/tensors-made-practical-for-engineers-and-data-teams-with-pytorch.png\",\"contentUrl\":\"\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/tensors-made-practical-for-engineers-and-data-teams-with-pytorch.png\",\"width\":1536,\"height\":1024},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/09\\\/18\\\/get-started-with-tensors-with-pytorch\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Get Started With Tensors With PyTorch\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/#website\",\"url\":\"https:\\\/\\\/cloudproinc.com.au\\\/\",\"name\":\"Cloud Pro Inc - CPI Consulting Pty Ltd\",\"description\":\"Cloud, AI &amp; Cybersecurity Consulting | Melbourne\",\"publisher\":{\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/cloudproinc.com.au\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/#organization\",\"name\":\"Cloud Pro Inc - Cloud Pro Inc - CPI Consulting Pty Ltd\",\"url\":\"https:\\\/\\\/cloudproinc.com.au\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/favfinalfile.png\",\"contentUrl\":\"\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/favfinalfile.png\",\"width\":500,\"height\":500,\"caption\":\"Cloud Pro Inc - Cloud Pro Inc - CPI Consulting Pty Ltd\"},\"image\":{\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/#\\\/schema\\\/person\\\/192eeeb0ce91062126ce3822ae88fe6e\",\"name\":\"CPI Staff\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g\",\"caption\":\"CPI Staff\"},\"sameAs\":[\"http:\\\/\\\/www.cloudproinc.com.au\"],\"url\":\"https:\\\/\\\/cloudproinc.com.au\\\/index.php\\\/author\\\/cpiadmin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Get Started With Tensors With PyTorch - CPI Consulting","description":"Learn to get started with tensors with PyTorch. Master tensor creation and operations with easy examples for real projects.","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:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/18\/get-started-with-tensors-with-pytorch\/","og_locale":"en_US","og_type":"article","og_title":"Get Started With Tensors With PyTorch","og_description":"Learn to get started with tensors with PyTorch. Master tensor creation and operations with easy examples for real projects.","og_url":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/18\/get-started-with-tensors-with-pytorch\/","og_site_name":"CPI Consulting","article_published_time":"2025-09-18T00:42:38+00:00","article_modified_time":"2025-09-18T00:42:41+00:00","og_image":[{"width":1024,"height":683,"url":"https:\/\/cloudproinc.com.au\/wp-content\/uploads\/2025\/09\/tensors-made-practical-for-engineers-and-data-teams-with-pytorch-1024x683.png","type":"image\/png"}],"author":"CPI Staff","twitter_card":"summary_large_image","twitter_misc":{"Written by":"CPI Staff","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/18\/get-started-with-tensors-with-pytorch\/#article","isPartOf":{"@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/18\/get-started-with-tensors-with-pytorch\/"},"author":{"name":"CPI Staff","@id":"https:\/\/cloudproinc.com.au\/#\/schema\/person\/192eeeb0ce91062126ce3822ae88fe6e"},"headline":"Get Started With Tensors With PyTorch","datePublished":"2025-09-18T00:42:38+00:00","dateModified":"2025-09-18T00:42:41+00:00","mainEntityOfPage":{"@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/18\/get-started-with-tensors-with-pytorch\/"},"wordCount":670,"commentCount":0,"publisher":{"@id":"https:\/\/cloudproinc.com.au\/#organization"},"image":{"@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/18\/get-started-with-tensors-with-pytorch\/#primaryimage"},"thumbnailUrl":"\/wp-content\/uploads\/2025\/09\/tensors-made-practical-for-engineers-and-data-teams-with-pytorch.png","articleSection":["AI","Blog","PyTorch"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/18\/get-started-with-tensors-with-pytorch\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/18\/get-started-with-tensors-with-pytorch\/","url":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/18\/get-started-with-tensors-with-pytorch\/","name":"Get Started With Tensors With PyTorch - CPI Consulting","isPartOf":{"@id":"https:\/\/cloudproinc.com.au\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/18\/get-started-with-tensors-with-pytorch\/#primaryimage"},"image":{"@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/18\/get-started-with-tensors-with-pytorch\/#primaryimage"},"thumbnailUrl":"\/wp-content\/uploads\/2025\/09\/tensors-made-practical-for-engineers-and-data-teams-with-pytorch.png","datePublished":"2025-09-18T00:42:38+00:00","dateModified":"2025-09-18T00:42:41+00:00","description":"Learn to get started with tensors with PyTorch. Master tensor creation and operations with easy examples for real projects.","breadcrumb":{"@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/18\/get-started-with-tensors-with-pytorch\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/18\/get-started-with-tensors-with-pytorch\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/18\/get-started-with-tensors-with-pytorch\/#primaryimage","url":"\/wp-content\/uploads\/2025\/09\/tensors-made-practical-for-engineers-and-data-teams-with-pytorch.png","contentUrl":"\/wp-content\/uploads\/2025\/09\/tensors-made-practical-for-engineers-and-data-teams-with-pytorch.png","width":1536,"height":1024},{"@type":"BreadcrumbList","@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/09\/18\/get-started-with-tensors-with-pytorch\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.cloudproinc.com.au\/"},{"@type":"ListItem","position":2,"name":"Get Started With Tensors With PyTorch"}]},{"@type":"WebSite","@id":"https:\/\/cloudproinc.com.au\/#website","url":"https:\/\/cloudproinc.com.au\/","name":"Cloud Pro Inc - CPI Consulting Pty Ltd","description":"Cloud, AI &amp; Cybersecurity Consulting | Melbourne","publisher":{"@id":"https:\/\/cloudproinc.com.au\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cloudproinc.com.au\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/cloudproinc.com.au\/#organization","name":"Cloud Pro Inc - Cloud Pro Inc - CPI Consulting Pty Ltd","url":"https:\/\/cloudproinc.com.au\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudproinc.com.au\/#\/schema\/logo\/image\/","url":"\/wp-content\/uploads\/2022\/01\/favfinalfile.png","contentUrl":"\/wp-content\/uploads\/2022\/01\/favfinalfile.png","width":500,"height":500,"caption":"Cloud Pro Inc - Cloud Pro Inc - CPI Consulting Pty Ltd"},"image":{"@id":"https:\/\/cloudproinc.com.au\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/cloudproinc.com.au\/#\/schema\/person\/192eeeb0ce91062126ce3822ae88fe6e","name":"CPI Staff","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g","caption":"CPI Staff"},"sameAs":["http:\/\/www.cloudproinc.com.au"],"url":"https:\/\/cloudproinc.com.au\/index.php\/author\/cpiadmin\/"}]}},"jetpack_featured_media_url":"\/wp-content\/uploads\/2025\/09\/tensors-made-practical-for-engineers-and-data-teams-with-pytorch.png","jetpack-related-posts":[{"id":53929,"url":"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/25\/turn-a-list-into-a-tensor-in-python\/","url_meta":{"origin":53893,"position":0},"title":"Turn a List into a Tensor in Python","author":"CPI Staff","date":"September 25, 2025","format":false,"excerpt":"Learn how to convert Python lists into tensors using NumPy, PyTorch, and TensorFlow, with tips on shapes, dtypes, performance, and common pitfalls.","rel":"","context":"In &quot;AI&quot;","block_context":{"text":"AI","link":"https:\/\/cloudproinc.com.au\/index.php\/category\/ai\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/09\/turn-a-list-into-a-tensor-in-python-with-numpy-pytorch-tensorflow.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/09\/turn-a-list-into-a-tensor-in-python-with-numpy-pytorch-tensorflow.png 1x, \/wp-content\/uploads\/2025\/09\/turn-a-list-into-a-tensor-in-python-with-numpy-pytorch-tensorflow.png 1.5x, \/wp-content\/uploads\/2025\/09\/turn-a-list-into-a-tensor-in-python-with-numpy-pytorch-tensorflow.png 2x, \/wp-content\/uploads\/2025\/09\/turn-a-list-into-a-tensor-in-python-with-numpy-pytorch-tensorflow.png 3x, \/wp-content\/uploads\/2025\/09\/turn-a-list-into-a-tensor-in-python-with-numpy-pytorch-tensorflow.png 4x"},"classes":[]},{"id":53890,"url":"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/18\/the-autonomy-of-tensors\/","url_meta":{"origin":53893,"position":1},"title":"The Autonomy of Tensors","author":"CPI Staff","date":"September 18, 2025","format":false,"excerpt":"Tensors are more than arrays\u2014they carry rules, gradients, and placement hints. Learn how their autonomy drives speed and reliability, and how to harness it across training, inference, and scale.","rel":"","context":"In &quot;AI&quot;","block_context":{"text":"AI","link":"https:\/\/cloudproinc.com.au\/index.php\/category\/ai\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/09\/the-autonomy-of-tensors-for-smarter-faster-ml-systems-today.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/09\/the-autonomy-of-tensors-for-smarter-faster-ml-systems-today.png 1x, \/wp-content\/uploads\/2025\/09\/the-autonomy-of-tensors-for-smarter-faster-ml-systems-today.png 1.5x, \/wp-content\/uploads\/2025\/09\/the-autonomy-of-tensors-for-smarter-faster-ml-systems-today.png 2x, \/wp-content\/uploads\/2025\/09\/the-autonomy-of-tensors-for-smarter-faster-ml-systems-today.png 3x, \/wp-content\/uploads\/2025\/09\/the-autonomy-of-tensors-for-smarter-faster-ml-systems-today.png 4x"},"classes":[]},{"id":53865,"url":"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/15\/loading-and-saving-pytorch-weights\/","url_meta":{"origin":53893,"position":2},"title":"Loading and Saving PyTorch Weights","author":"CPI Staff","date":"September 15, 2025","format":false,"excerpt":"Learn practical, safe patterns for saving, loading, and resuming PyTorch models. We cover state_dicts, checkpoints, device mapping, distributed training, and common pitfalls.","rel":"","context":"In &quot;AI&quot;","block_context":{"text":"AI","link":"https:\/\/cloudproinc.com.au\/index.php\/category\/ai\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/09\/best-practices-for-loading-and-saving-pytorch-weights-in-production.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/09\/best-practices-for-loading-and-saving-pytorch-weights-in-production.png 1x, \/wp-content\/uploads\/2025\/09\/best-practices-for-loading-and-saving-pytorch-weights-in-production.png 1.5x, \/wp-content\/uploads\/2025\/09\/best-practices-for-loading-and-saving-pytorch-weights-in-production.png 2x, \/wp-content\/uploads\/2025\/09\/best-practices-for-loading-and-saving-pytorch-weights-in-production.png 3x, \/wp-content\/uploads\/2025\/09\/best-practices-for-loading-and-saving-pytorch-weights-in-production.png 4x"},"classes":[]},{"id":53914,"url":"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/21\/run-pytorch-in-net-with-torchsharp\/","url_meta":{"origin":53893,"position":3},"title":"Run PyTorch in .NET with TorchSharp","author":"CPI Staff","date":"September 21, 2025","format":false,"excerpt":"Build and ship PyTorch models in .NET using TorchSharp, ONNX, or a Python service. Practical steps, code, and deployment tips for teams on Windows, Linux, and containers.","rel":"","context":"In &quot;.NET&quot;","block_context":{"text":".NET","link":"https:\/\/cloudproinc.com.au\/index.php\/category\/net\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/09\/practical-ways-to-run-pytorch-in-net-with-torchsharp-and-more.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/09\/practical-ways-to-run-pytorch-in-net-with-torchsharp-and-more.png 1x, \/wp-content\/uploads\/2025\/09\/practical-ways-to-run-pytorch-in-net-with-torchsharp-and-more.png 1.5x, \/wp-content\/uploads\/2025\/09\/practical-ways-to-run-pytorch-in-net-with-torchsharp-and-more.png 2x, \/wp-content\/uploads\/2025\/09\/practical-ways-to-run-pytorch-in-net-with-torchsharp-and-more.png 3x, \/wp-content\/uploads\/2025\/09\/practical-ways-to-run-pytorch-in-net-with-torchsharp-and-more.png 4x"},"classes":[]},{"id":53721,"url":"https:\/\/cloudproinc.com.au\/index.php\/2025\/08\/27\/what-are-tensors-in-ai-and-large-language-models-llms\/","url_meta":{"origin":53893,"position":4},"title":"What Are Tensors in AI and Large Language Models (LLMs)?","author":"CPI Staff","date":"August 27, 2025","format":false,"excerpt":"In this post \"What Are Tensors in AI and Large Language Models (LLMs)?\", we\u2019ll explore what tensors are, how they are used in AI and LLMs, and why they matter for organizations looking to leverage machine learning effectively. Artificial Intelligence (AI) and Large Language Models (LLMs) like GPT-4 or LLaMA\u2026","rel":"","context":"In &quot;AI&quot;","block_context":{"text":"AI","link":"https:\/\/cloudproinc.com.au\/index.php\/category\/ai\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/08\/what-are-tensors-in-ai-and-large-language-models-llms.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/08\/what-are-tensors-in-ai-and-large-language-models-llms.png 1x, \/wp-content\/uploads\/2025\/08\/what-are-tensors-in-ai-and-large-language-models-llms.png 1.5x, \/wp-content\/uploads\/2025\/08\/what-are-tensors-in-ai-and-large-language-models-llms.png 2x, \/wp-content\/uploads\/2025\/08\/what-are-tensors-in-ai-and-large-language-models-llms.png 3x, \/wp-content\/uploads\/2025\/08\/what-are-tensors-in-ai-and-large-language-models-llms.png 4x"},"classes":[]},{"id":53932,"url":"https:\/\/cloudproinc.com.au\/index.php\/2025\/09\/25\/mastering-common-tensor-operations\/","url_meta":{"origin":53893,"position":5},"title":"Mastering Common Tensor Operations","author":"CPI Staff","date":"September 25, 2025","format":false,"excerpt":"A practical guide to the tensor operations that power modern AI. Learn the essentials, from shapes and broadcasting to vectorization, autograd, and GPU performance.","rel":"","context":"In &quot;AI&quot;","block_context":{"text":"AI","link":"https:\/\/cloudproinc.com.au\/index.php\/category\/ai\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/09\/mastering-common-tensor-operations-for-ai-and-data-workloads.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/09\/mastering-common-tensor-operations-for-ai-and-data-workloads.png 1x, \/wp-content\/uploads\/2025\/09\/mastering-common-tensor-operations-for-ai-and-data-workloads.png 1.5x, \/wp-content\/uploads\/2025\/09\/mastering-common-tensor-operations-for-ai-and-data-workloads.png 2x, \/wp-content\/uploads\/2025\/09\/mastering-common-tensor-operations-for-ai-and-data-workloads.png 3x, \/wp-content\/uploads\/2025\/09\/mastering-common-tensor-operations-for-ai-and-data-workloads.png 4x"},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/posts\/53893","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/comments?post=53893"}],"version-history":[{"count":2,"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/posts\/53893\/revisions"}],"predecessor-version":[{"id":53897,"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/posts\/53893\/revisions\/53897"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/media\/53894"}],"wp:attachment":[{"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/media?parent=53893"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/categories?post=53893"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/tags?post=53893"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}