python实验命令行常用操作

(base) PS C:\Users\chenxuqi> conda info -e
# conda environments:
#
base                  *  D:\anaconda3
pytorch_1_2_0_cu100      D:\anaconda3\envs\pytorch_1_2_0_cu100
pytorch_1_5_1_cu101      D:\anaconda3\envs\pytorch_1_5_1_cu101
pytorch_1_7_1_cu101      D:\anaconda3\envs\pytorch_1_7_1_cu101
pytorch_1_9_0_cu111      D:\anaconda3\envs\pytorch_1_9_0_cu111
web_crawler              D:\anaconda3\envs\web_crawler

(base) PS C:\Users\chenxuqi> conda env list
# conda environments:
#
base                  *  D:\anaconda3
pytorch_1_2_0_cu100      D:\anaconda3\envs\pytorch_1_2_0_cu100
pytorch_1_5_1_cu101      D:\anaconda3\envs\pytorch_1_5_1_cu101
pytorch_1_7_1_cu101      D:\anaconda3\envs\pytorch_1_7_1_cu101
pytorch_1_9_0_cu111      D:\anaconda3\envs\pytorch_1_9_0_cu111
web_crawler              D:\anaconda3\envs\web_crawler

(base) PS C:\Users\chenxuqi>
conda activate base
conda deactivate

conda activate web_crawler
conda deactivate

conda activate pytorch_1_2_0_cu100
conda deactivate

conda activate pytorch_1_5_1_cu101
conda deactivate

conda activate pytorch_1_7_1_cu101
conda deactivate

conda activate pytorch_1_9_0_cu111
conda deactivate

代码实验展示:

a += 2 和 a = a + 2 的区别:
Microsoft Windows [版本 10.0.18363.1316]
(c) 2019 Microsoft Corporation。保留所有权利。

C:\Users\chenxuqi>conda activate ssd4pytorch1_2_0

(ssd4pytorch1_2_0) C:\Users\chenxuqi>python
Python 3.7.7 (default, May  6 2020, 11:45:54) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.manual_seed(seed=20200910)
<torch._C.Generator object at 0x000002B1227FD330>
>>>
>>> a = torch.randn(3,4,requires_grad=True)
>>> a
tensor([[ 0.2824, -0.3715,  0.9088, -1.7601],
        [-0.1806,  2.0937,  1.0406, -1.7651],
        [ 1.1216,  0.8440,  0.1783,  0.6859]], requires_grad=True)
>>> a = a + 2
>>> a
tensor([[2.2824, 1.6285, 2.9088, 0.2399],
        [1.8194, 4.0937, 3.0406, 0.2349],
        [3.1216, 2.8440, 2.1783, 2.6859]], grad_fn=<AddBackward0>)
>>> a += 2
>>> a
tensor([[4.2824, 3.6285, 4.9088, 2.2399],
        [3.8194, 6.0937, 5.0406, 2.2349],
        [5.1216, 4.8440, 4.1783, 4.6859]], grad_fn=<AddBackward0>)
>>>
>>> torch.manual_seed(seed=20200910)
<torch._C.Generator object at 0x000002B1227FD330>
>>>
>>> a = torch.randn(3,4,requires_grad=True)
>>> a
tensor([[ 0.2824, -0.3715,  0.9088, -1.7601],
        [-0.1806,  2.0937,  1.0406, -1.7651],
        [ 1.1216,  0.8440,  0.1783,  0.6859]], requires_grad=True)
>>> a += 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: a leaf Variable that requires grad has been used in an in-place operation.
>>>
>>>
>>>
>>> ^Z


(ssd4pytorch1_2_0) C:\Users\chenxuqi>conda activate pytorch_1.7.1_cu102

(pytorch_1.7.1_cu102) C:\Users\chenxuqi>python
Python 3.7.9 (default, Aug 31 2020, 17:10:11) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.manual_seed(seed=20200910)
<torch._C.Generator object at 0x000002366AF76870>
>>>
>>> a = torch.randn(3,4,requires_grad=True)
>>> a
tensor([[ 0.2824, -0.3715,  0.9088, -1.7601],
        [-0.1806,  2.0937,  1.0406, -1.7651],
        [ 1.1216,  0.8440,  0.1783,  0.6859]], requires_grad=True)
>>> a = a + 2
>>> a
tensor([[2.2824, 1.6285, 2.9088, 0.2399],
        [1.8194, 4.0937, 3.0406, 0.2349],
        [3.1216, 2.8440, 2.1783, 2.6859]], grad_fn=<AddBackward0>)
>>> a += 2
>>> a
tensor([[4.2824, 3.6285, 4.9088, 2.2399],
        [3.8194, 6.0937, 5.0406, 2.2349],
        [5.1216, 4.8440, 4.1783, 4.6859]], grad_fn=<AddBackward0>)
>>>
>>> torch.manual_seed(seed=20200910)
<torch._C.Generator object at 0x000002366AF76870>
>>>
>>> a = torch.randn(3,4,requires_grad=True)
>>> a
tensor([[ 0.2824, -0.3715,  0.9088, -1.7601],
        [-0.1806,  2.0937,  1.0406, -1.7651],
        [ 1.1216,  0.8440,  0.1783,  0.6859]], requires_grad=True)
>>> a += 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: a leaf Variable that requires grad is being used in an in-place operation.
>>>
>>>
>>>
>>>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值