Pytorch 7多维

多维读取

numpy

python 复制代码
xy = np.loadtxt('diabetes.csv', delimiter=',', dtype=np.float32)

print("input data.shape", x_data.shape)
x_data = torch.from_numpy(xy[:, :-1])# 选择所有行不包括最后一列
y_data = torch.from_numpy(xy[:, [-1]])# 选择所有行,只有最后一列
np.loadtxt(fname, dtype=float, delimiter=' ', comments='#', skiprows=0, usecols=None, unpack=False, ndmin=0, encoding='bytes', max_rows=None)
# 参数分别是路径,dtype: 数据类型,默认为 float。delimiter: 分隔符,默认为空格。用于分隔文件中的数据列skiprows: 要跳过的行数,默认为 0。用于跳过文件开头的标题行或其他不需要的行。

多维多层数类

python 复制代码
class Model(torch.nn.Module):
    def __init__(self):
        super(Model, self).__init__()
        self.linear1 = torch.nn.Linear(8, 6)
        self.linear2 = torch.nn.Linear(6, 4)
        self.linear3 = torch.nn.Linear(4, 2)
        self.linear4 = torch.nn.Linear(2, 1)
        self.sigmoid = torch.nn.Sigmoid()
 
    def forward(self, x):
        x = self.sigmoid(self.linear1(x))
        x = self.sigmoid(self.linear2(x))
        x = self.sigmoid(self.linear3(x)) # y hat
        x = self.sigmoid(self.linear4(x))  # y hat
        return x

这里维度由输入数据决定

后面基本上一样

python 复制代码
torch.eq(a,b).sum().item()# 把a和b相等的返回1否则为0,求和,item是转化为py的数据0维
相关推荐
Li emily1 小时前
解决了加密货币api多币种订阅时的数据乱序问题
人工智能·python·api·fastapi
山川绿水1 小时前
bugku——PWN——overflow2
人工智能·web安全·网络安全
程序员cxuan2 小时前
微信读书官方发了 skills,把我给秀麻了。
人工智能·后端·程序员
2301_781571422 小时前
Golang格式化输出占位符都有什么_Golang fmt占位符教程【通俗】
jvm·数据库·python
fake_ss1982 小时前
AI时代学习全栈项目开发的新范式
java·人工智能·学习·架构·个人开发·学习方法
asdzx672 小时前
使用 Python 为 PDF 添加页码 (详细教程)
python·pdf·页码
nassi_2 小时前
对AI工程问题的一些思考
大数据·人工智能·hadoop
AI技术控2 小时前
《Transformers are Inherently Succinct》论文解读:从“能表达什么”到“多紧凑地表达”
人工智能·python·深度学习·机器学习·自然语言处理
蔡俊锋2 小时前
AI记忆压缩术:从305GB到7.4GB的魔法
人工智能·ai·ai 记忆
Upsy-Daisy2 小时前
AI Agent 项目学习笔记(二):Spring AI 与 ChatClient 主链路解析
人工智能·笔记·学习