- Deep Learning with PyTorch Quick Start Guide
- David Julian
- 273字
- 2021-07-02 15:00:10
Basic PyTorch operations
Tensors are the workhorse of PyTorch. If you know linear algebra, they are equivalent to a matrix. Torch tensors are effectively an extension of the numpy.array object. Tensors are an essential conceptual component in deep learning systems, so having a good understanding of how they work is important.
In our first example, we will be looking at tensors of size 2 x 3. In PyTorch, we can create tensors in the same way that we create NumPy arrays. For example, we can pass them nested lists, as shown in the following code:

Here we have created two tensors, each with dimensions of 2 x 3. You can see that we have created a simple linear function (more about linear functions in Chapter 2, Deep Learning Fundamentals) and applied it to x and y and printed out the result. We can visualize this with the following diagram:

As you may know from linear algebra, matrix multiplication and addition occur element-wise so that for the first element of x, let's write this as X00. This is multiplied by two and added to the first element of y, written as Y00, giving F00 = 9. X01 = 2 and Y01 = 8 so f01 = 4 + 12. Notice that the indices start at zero.
If you have never seen any linear algebra, don't worry too much about this, as we are going to brush up on these concepts in Chapter 2, Deep Learning Fundamentals, and you will get to practice with Python indexing shortly. For now, just consider our 2 x 3 tensors as tables with numbers in them.
- 32位嵌入式系統(tǒng)與SoC設(shè)計(jì)導(dǎo)論
- 輕松學(xué)C語言
- 21小時(shí)學(xué)通AutoCAD
- Div+CSS 3.0網(wǎng)頁布局案例精粹
- 軟件架構(gòu)設(shè)計(jì)
- 自動(dòng)控制原理
- Enterprise PowerShell Scripting Bootcamp
- 突破,Objective-C開發(fā)速學(xué)手冊
- 在實(shí)戰(zhàn)中成長:Windows Forms開發(fā)之路
- R Machine Learning Projects
- Silverlight 2完美征程
- MPC5554/5553微處理器揭秘
- FANUC工業(yè)機(jī)器人配置與編程技術(shù)
- Hands-On DevOps
- PHP求職寶典