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

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:

主站蜘蛛池模板: 成武县| 大埔县| 岐山县| 胶州市| 昌吉市| 伊宁县| 偃师市| 灵丘县| 枞阳县| 普兰店市| 普宁市| 永州市| 监利县| 濮阳县| 收藏| 鹰潭市| 闽侯县| 微博| 吴川市| 巴马| 承德县| 拜城县| 驻马店市| 克东县| 临西县| 常宁市| 万全县| 繁峙县| 通榆县| 普兰店市| 海安县| 韶山市| 收藏| 勃利县| 兰州市| 梅州市| 府谷县| 五大连池市| 兴安县| 松潘县| 东乡|