[实验笔记] 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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值