Python学习记录1
1.append()——在数组后加上相应的元素
例子
a=[1,2,3]
a.append(4)
输出结果为[1,2,3,4]
2.torch.zeros()
import torch
a=torch.zeros(3)
print(a)
#输出:
tensor([0., 0., 0.])
A=torch.zeros(3,3)
print(A)
#输出:
tensor([[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]])
3.torch.ones()
import torch
b=torch.ones(3)
print(b)
#输出:
tensor([1., 1., 1.])
B=torch.ones(3,3)
print(B)
#输出:
tensor([[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.]])
4.torch.log()——以自然数e为底的对数函数
import torch
c=torch.log(b)
print(c)
#输出:
tensor([0., 0., 0.])
torch.Tensor([3.6])
#输出:
tensor([3.6000])
torch.log(torch.Tensor([3.6]))
#输出:
tensor([1.2809])
5.torch.from_numpy()——将数组array转为Tensor类型
import numpy as np
import torch
a1=np.array([1,2,3])
b1=torch.from_numpy(a1)
print(a1)
#输出:
[1 2 3]
print(b1)
#输出:
tensor([1, 2, 3], dtype=torch.int32)