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

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:

主站蜘蛛池模板: 鄂托克前旗| 吉木萨尔县| 阜平县| 武邑县| 弥渡县| 浦北县| 全南县| 太保市| 金阳县| 通江县| 黔西| 鸡泽县| 广东省| 靖州| 确山县| 克什克腾旗| 南开区| 汤阴县| 静宁县| 翼城县| 新巴尔虎左旗| 饶阳县| 怀宁县| 吴堡县| 门头沟区| 满城县| 班玛县| 定州市| 麟游县| 开阳县| 广南县| 忻城县| 那坡县| 谷城县| 新蔡县| 金阳县| 古丈县| 苍山县| 新巴尔虎左旗| 彭水| 靖西县|