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

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:

主站蜘蛛池模板: 永靖县| 邵阳县| 杭锦后旗| 临朐县| 赤水市| 五指山市| 上栗县| 赣榆县| 金秀| 武鸣县| 锡林郭勒盟| 上林县| 上饶市| 家居| 丘北县| 双辽市| 林州市| 南华县| 宜章县| 台东市| 鹤庆县| 介休市| 滁州市| 吉木萨尔县| 德安县| 宁远县| 定结县| 林口县| 皋兰县| 冕宁县| 瑞昌市| 阳江市| 锡林郭勒盟| 阿鲁科尔沁旗| 扶沟县| 昭觉县| 巩留县| 宁波市| 元朗区| 同德县| 梁河县|