官术网_书友最值得收藏!

In place operations

It is important to understand the difference between in place and assignment operations. When, for example, we use transpose(x), a value is returned but the value of x does not change. In all the examples up until now, we have been performing operations by assignment. That is, we have been assigning a variable to the result of an operation, or simply printing it to the output, as in the preceding example. In either case, the original variable remains untouched. Alternatively, we may need to apply an operation in place. We can, of course, assign a variable to itself, such as in x = x.transpose(0,1); however, a more convenient way to do this is with in place operations. In general, in place operations in PyTorch have a trailing underscore. For an example, see the following code:

As another example, here is the linear function we started this chapter with using in place operations on y:

主站蜘蛛池模板: 凌源市| 扶绥县| 雷山县| 扶风县| 翁源县| 碌曲县| 泉州市| 泸州市| 米脂县| 嵊泗县| 九寨沟县| 定州市| 星子县| 库尔勒市| 饶河县| 大埔区| 城步| 宽甸| 冕宁县| 永福县| 延津县| 偃师市| 武夷山市| 赤峰市| 慈溪市| 泽州县| 龙海市| 威海市| 潜山县| 黄骅市| 和田县| 三原县| 沛县| 比如县| 九江市| 策勒县| 余江县| 册亨县| 四子王旗| 祁阳县| 商洛市|