- 博客(7)
- 收藏
- 关注
原创 pytorch torch.uint8的用法及uint8求和sum()
uint8是8位的,表示十进制数0-255,如果大于255则进一位,例如256显示就变成0示例代码如下c=256a=torch.tensor(1,dtype=torch.uint8)tensor=[a for i in range(c)]print(sum(tensor))结果tensor(0, dtype=torch.uint8)改正方法对uint8求和要使用...
2019-07-15 09:38:41 13250
原创 Pytorch tensor.view_as的用法
示例代码import torcha=torch.tensor([1,2,3])b=torch.tensor([2,2,4])print(a.detach().view_as(b))一般是用来做比较的时候使用,确保两个比较的数据,维度是一致的。...
2019-07-15 08:53:09 3566
原创 pytorch KeyError: tensor(1)
pytorch中的tensor不能作为字典的键,输入下面代码会产生错误import torch'''pytorch中的tensor和list不能混用'''a=torch.tensor([1,2,4])b={1:'a',2:'b',4:'d'}c=[b[o] for o in a]print(c)KeyError: tensor(1)正确的是要在循环中临时转成nump...
2019-07-14 20:56:41 8010 3
原创 RuntimeError: Expected object of scalar type Float but got scalar type Int for argument #2 'other'
不同类型的是不相等的,并且无法比较import torcha=torch.tensor([1],dtype=torch.float)b=torch.tensor([1],dtype=torch.int)#tensor 的1无论什么情况都与普通的1相等#不同类型的是不相等的,并且无法比较if a==b: print((a==b)) print((a==b).long(...
2019-07-14 20:41:06 4711
原创 【TensorFlow】tf.concat()的用法
tf.concat()是连接两个矩阵的操作。tf.concat(values,concat_dim, name='concat')concat_dim代表对矩阵按照某一维度进行操作。concat_dim=0是按行对矩阵进行拼接。import tensorflow as tft1 = [[1, 2, 3], [4, 5, 6]]t2 = [[7, 8, 9], [10, 11,...
2018-10-10 15:14:57 322
原创 tf.expand_dims()使用
tf.expand_dims( input, axis=None, name=None, dim=None)他所实现的功能是给定一个input,在axis轴处给input增加一个为1的维度。举个栗子:# 't2' is a tensor of shape [2, 3, 5]tf.shape(tf.expand_dims(t2, 0)) #...
2018-09-21 17:14:07 15578 2
原创 x[0] for x in counter.items()的使用
c是类Counter的实例化。c.item()是将字典转化成列表,这个列表的每个元素是一个元组。而我们又需要提取元组的第一位。代码如下:from collections import Counterc = Counter('adccbccdf')print(c)print(c.items())word_counts = [x for x in c.items()]word=[x...
2018-09-12 16:40:09 2719
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人