Python学习笔记(3)

2018-11-16  本文已影响0人  Yankee_13

一、对于矩阵:

~x=tensor([[0, 1, 2, 3, 4],

                [5, 6, 7, 8, 9]], dtype=torch.int32)

~print(x[:,1])

输出结果为[1,6],应该比较好理解吧

二、避免浅拷贝的方法:

    matrix= [[1 for i in range(n)]for i in range(m)]

    这样来初始化矩阵可以避免浅拷贝

    https://blog.csdn.net/edogawachia/article/details/79762310

    http://www.runoob.com/w3cnote/python-understanding-dict-copy-shallow-or-deep.html

三、控制GPU使用

    os.environ["CUDA_VISIBLE_DEVICES"] ="0"

    指定使用GPU"0"

四、字典get函数

    dict.get(key, default=None)

    Python 字典(Dictionary) get() 函数返回指定键的值,如果值不在字典中返回默认值。

上一篇 下一篇

猜你喜欢

热点阅读