pytorch基礎函式

2021-10-01 02:57:43 字數 517 閱讀 7449

返回乙個張量,從標準正態分佈(均值為0,方差為1)中抽取的一組隨機數。張量的形狀由引數sizes定義。

import torch

import torch.nn.functional as f

x1= torch.tensor( [ [1,2,3,4],[1,3,4,5],[3,4,5,6]])

y11= f.softmax(x, dim = 0) #對每一列進行softmax

y12 = f.softmax(x,dim =1) #對每一行進行softmax

x2 = torch.tensor([1,2,3,4])

y2 = f.softmax(x2,dim=0)

Pytorch基礎操作

import torch import numpy as np x torch.empty 5,3 print x 初始化乙個隨機矩陣 x torch.zeros 5,3,dtype torch.long print x 構建乙個全0矩陣 x x.new ones 5,3,dtype torch.d...

pytorch基礎用法

1.把x0和x1的資料合在一起,宣告是什麼型別的資料集 x torch.cat x0,x1 0 type torch.floattensor shape 200,2 floattensor 32 bit floating y torch.cat y0,y1 type torch.longtensor...

pytorch基礎練習

colab自帶pytorch,是不是很方便!順便,感謝xzy和mds大佬提供的幫助 參考部落格 我猜一定有人想要 吧 import torch x torch.empty 5,3 print x 建立乙個沒有初始化的矩陣 y torch.rand 5,3 print y 建立乙個隨機初始化的矩陣 z...