pytorch:tensor類型的構(gòu)建與相互轉(zhuǎn)換實例-創(chuàng)新互聯(lián)

Summary

在城東等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供網(wǎng)站建設(shè)、網(wǎng)站制作 網(wǎng)站設(shè)計制作定制網(wǎng)站設(shè)計,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站設(shè)計,營銷型網(wǎng)站,成都外貿(mào)網(wǎng)站建設(shè)公司,城東網(wǎng)站建設(shè)費用合理。

主要包括以下三種途徑:

使用獨立的函數(shù);

使用torch.type()函數(shù);

使用type_as(tesnor)將張量轉(zhuǎn)換為給定類型的張量。

使用獨立函數(shù)

import torch

tensor = torch.randn(3, 5)
print(tensor)

# torch.long() 將tensor投射為long類型
long_tensor = tensor.long()
print(long_tensor)

# torch.half()將tensor投射為半精度浮點類型
half_tensor = tensor.half()
print(half_tensor)

# torch.int()將該tensor投射為int類型
int_tensor = tensor.int()
print(int_tensor)

# torch.double()將該tensor投射為double類型
double_tensor = tensor.double()
print(double_tensor)

# torch.float()將該tensor投射為float類型
float_tensor = tensor.float()
print(float_tensor)

# torch.char()將該tensor投射為char類型
char_tensor = tensor.char()
print(char_tensor)

# torch.byte()將該tensor投射為byte類型
byte_tensor = tensor.byte()
print(byte_tensor)

# torch.short()將該tensor投射為short類型
short_tensor = tensor.short()
print(short_tensor)

分享標(biāo)題:pytorch:tensor類型的構(gòu)建與相互轉(zhuǎn)換實例-創(chuàng)新互聯(lián)
本文網(wǎng)址:http://muchs.cn/article32/dphhpc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站網(wǎng)站內(nèi)鏈、網(wǎng)站營銷微信小程序、用戶體驗、品牌網(wǎng)站設(shè)計

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作