[实验笔记] pytorch tensor和numpy的一些操作函数

1. tensor.mean(),取算术平均值。指定参数可以计算每一行或者 每一列的算术平均数

2. tensor.unsqueeze(i): 在某个维度(从0开始)增加一个维度。squeeze(i)去掉某一维度

3.numpy转tensor时的Double Tensor 和Float Tensor 不一致:对numpy用astype(np.float32)可以解决

RuntimeError: Expected object of type torch.DoubleTensor but found type torch.FloatTensor for argument #2 'weight'

4.numpy和tensor转换:

List转numpy.array:

temp = np.array(list) 

numpy.array转List:

arr = temp.tolist() 

5.numpy升降维:https://www.jianshu.com/p/fd526675c7b7

  • numpy的升维
    将(2,)变成(2,1)
a = np.array([1,2])
b = np.expand_dims(a, axis=1)
a = np.array([[1],[2]])
b = np.squeeze(a)


6.numpy数组拼接:https://blog.csdn.net/c_living/article/details/85264047
a -> 转成list(a) ->  lista.extend(listb) ->  a = np.array(lista)

7.numpy数组降维:np.array(a),a.reshape(2000)..

8.RuntimeError: dimension out of range (expected to be in range of [-1, 0], but got 1)

https://blog.csdn.net/qq_40178291/article/details/100183457

---------------------待更新

2.pycharm查看函数:ctrl+鼠标点击

3.pycharm全项目搜素:ctrl+shift+f

4.

发布了22 篇原创文章 · 获赞 6 · 访问量 5225

猜你喜欢

转载自blog.csdn.net/qq_38362788/article/details/103180357