日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

在 tensorflow 和numpy 中矩阵的加法

發(fā)布時(shí)間:2025/4/5 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 在 tensorflow 和numpy 中矩阵的加法 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Am×n×..×km \times n \times ..\times km×n×..×k 和B1×k1\times k1×k 矩陣相加
相當(dāng)于在最后一個(gè)維度上map 依次相加A[-s:] for s in rang(k)
import numpy as np a=np.array(range(3*4)).reshape([3,4]) b=np.array([0.2]*4)print('a.shape=',a.shape) print('b.shape=',b.shape)print(a+b)print('-'*20+'我是分割線'+'-'*20) a=np.array(range(2*3*4)).reshape([2,3,4]) b=np.array([0.2]*4)print('a.shape=',a.shape) print('b.shape=',b.shape)print(a+b)

輸出

a.shape= (3, 4) b.shape= (1, 4) [[ 0.2 1.2 2.2 3.2][ 4.2 5.2 6.2 7.2][ 8.2 9.2 10.2 11.2]] --------------------我是分割線-------------------- a.shape= (2, 3, 4) b.shape= (1, 4) [[[ 0.2 1.2 2.2 3.2][ 4.2 5.2 6.2 7.2][ 8.2 9.2 10.2 11.2]][[12.2 13.2 14.2 15.2][16.2 17.2 18.2 19.2][20.2 21.2 22.2 23.2]]]
Am×n×..×p×km \times n \times ..\times p\times km×n×..×p×k 和Bp×kp\times kp×k 矩陣相加
相當(dāng)于在最后兩個(gè)維度的分塊加上B,A[-s:] for s in rang(p*k)
a=np.array(range(2*3*4)).reshape([2,3,4]) b=np.array(range(3*4)).reshape([3,4])*0.1print('a.shape=',a.shape) print('b.shape=',b.shape) print(a+b) a.shape= (2, 3, 4) b.shape= (3, 4) [[[ 0. 1.1 2.2 3.3][ 4.4 5.5 6.6 7.7][ 8.8 9.9 11. 12.1]][[12. 13.1 14.2 15.3][16.4 17.5 18.6 19.7][20.8 21.9 23. 24.1]]]
A2×3×42 \times 3\times 42×3×4 和B2×1×42 \times 1\times 42×1×4 矩陣相加
c[0]=a[0]+b[0],c[1]=a[1]+b[1]
a=np.array(range(2*3*4)).reshape([2,3,4]) b=np.array([[[9,9,9,9]],[[2,3,5,9]]]) c=a+b print('a.shape=',a.shape) print('b.shape=',b.shape)print(c) a.shape= (2, 3, 4) b.shape= (2, 1, 4) [[[ 9 10 11 12][13 14 15 16][17 18 19 20]][[14 16 19 24][18 20 23 28][22 24 27 32]]]

總結(jié)

以上是生活随笔為你收集整理的在 tensorflow 和numpy 中矩阵的加法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。