第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

PyTorch 相當(dāng)于 numpy reshape 函數(shù)

PyTorch 相當(dāng)于 numpy reshape 函數(shù)

犯罪嫌疑人X 2023-12-09 15:42:18
您好,我有這些函數(shù)來(lái)展平我的復(fù)雜類型數(shù)據(jù),將其提供給 NN 并將 NN 預(yù)測(cè)重建為原始形式。def flatten_input64(Input): #convert (:,4,4,2) complex matrix to (:,64) real vector  Input1 = Input.reshape(-1, 32, order='F')  Input_vector=np.zeros([19957,64],dtype = np.float64)  Input_vector[:,0:32] = Input1.real  Input_vector[:,32:64] = Input1.imag  return Input_vectordef convert_output64(Output): #convert (:,64) real vector to (:,4,4,2) complex matrix    Output1 = Output[:,0:32] + 1j * Output[:,32:64]  output_matrix = Output1.reshape(-1, 4 ,4 ,2 , order = 'F')  return output_matrix我正在編寫一個(gè)自定義損失,要求所有操作都在 torch 中,并且我應(yīng)該在 PyTorch 中重寫我的轉(zhuǎn)換函數(shù)。問題是 PyTorch 沒有“F”順序重塑。我嘗試編寫自己的 F reorder 版本,但是它不起作用。你知道我的錯(cuò)誤是什么嗎?def convert_output64_torch(input):   # number_of_samples = defined   for i in range(0, number_of_samples):     Output1 = input[i,0:32] + 1j * input[i,32:64]     Output2 = Output1.view(-1,4,4,2).permute(3,2,1,0)   if i == 0:     Output3 = Output2   else:     Output3 = torch.cat((Output3, Output2),0)return Output3更新:在 @a_guest 評(píng)論之后,我嘗試使用轉(zhuǎn)置和重塑來(lái)重新創(chuàng)建矩陣,并且我得到的代碼與 numy 中的 F 階重塑相同:def convert_output64_torch(input):   Output1 = input[:,0:32] + 1j * input[:,32:64]   shape = (-1 , 4 , 4 , 2)   Output3 = torch.transpose(torch.transpose(torch.reshape(torch.transpose(Output1,0,1),shape[::-1]),1,2),0,3)return Output3
查看完整描述

1 回答

?
MMMHUHU

TA貢獻(xiàn)1834條經(jīng)驗(yàn) 獲得超8個(gè)贊

在 Numpy 和 PyTorch 中,您可以通過以下操作獲得等效的結(jié)果:(a.T.reshape(shape[::-1]).T其中a是數(shù)組或張量):


>>> a = np.arange(16).reshape(4, 4)

>>> a

array([[ 0,  1,  2,  3],

       [ 4,  5,  6,  7],

       [ 8,  9, 10, 11],

       [12, 13, 14, 15]])

>>> shape = (2, 8)

>>> a.reshape(shape, order='F')

array([[ 0,  8,  1,  9,  2, 10,  3, 11],

       [ 4, 12,  5, 13,  6, 14,  7, 15]])

>>> a.T.reshape(shape[::-1]).T

array([[ 0,  8,  1,  9,  2, 10,  3, 11],

       [ 4, 12,  5, 13,  6, 14,  7, 15]])


查看完整回答
反對(duì) 回復(fù) 2023-12-09
  • 1 回答
  • 0 關(guān)注
  • 178 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)