tf.gather拼接

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/NockinOnHeavensDoor/article/details/84795678
mu = np.random.rand(5,5)
sigma = np.random.rand(5,5)

index = [[0, 1],[1,2]]
smu = sess.run(tf.gather(mu,index))
ssigma = sess.run(tf.gather(sigma,index))
print(smu)
print(ssigma)
print(ssigma.shape)

[[[0.67022627 0.25120792 0.02617609 0.51403094 0.15839324]
  [0.98799653 0.98736352 0.30693956 0.35410828 0.72678107]]

 [[0.98799653 0.98736352 0.30693956 0.35410828 0.72678107]
  [0.51550099 0.10428722 0.0297628  0.77017502 0.53493682]]]
[[[0.57900274 0.01917046 0.00688705 0.74225908 0.346025  ]
  [0.63816741 0.64569699 0.0029196  0.78463413 0.01966627]]

 [[0.63816741 0.64569699 0.0029196  0.78463413 0.01966627]
  [0.11854726 0.65260806 0.1544332  0.59858186 0.38596031]]]
(2, 2, 5)
print(smu[:,0],"\n\n",smu[:,1])
print("\n\n",ssigma[:,0],"\n\n",ssigma[:,1])
print(ssigma[:,1])
[[0.67022627 0.25120792 0.02617609 0.51403094 0.15839324]
 [0.98799653 0.98736352 0.30693956 0.35410828 0.72678107]] 

 [[0.98799653 0.98736352 0.30693956 0.35410828 0.72678107]
 [0.51550099 0.10428722 0.0297628  0.77017502 0.53493682]]


 [[0.57900274 0.01917046 0.00688705 0.74225908 0.346025  ]
 [0.63816741 0.64569699 0.0029196  0.78463413 0.01966627]] 

 [[0.63816741 0.64569699 0.0029196  0.78463413 0.01966627]
 [0.11854726 0.65260806 0.1544332  0.59858186 0.38596031]]
(2, 5)
x = sess.run(tf.concat((smu[:,0],ssigma[:,0]),axis=1))
y = sess.run(tf.concat((smu[:,1],ssigma[:,1]),axis=1))
print(x,"\n\n",y)
[[0.67022627 0.25120792 0.02617609 0.51403094 0.15839324 0.57900274
  0.01917046 0.00688705 0.74225908 0.346025  ]
 [0.98799653 0.98736352 0.30693956 0.35410828 0.72678107 0.63816741
  0.64569699 0.0029196  0.78463413 0.01966627]] 

 [[0.98799653 0.98736352 0.30693956 0.35410828 0.72678107 0.63816741
  0.64569699 0.0029196  0.78463413 0.01966627]
 [0.51550099 0.10428722 0.0297628  0.77017502 0.53493682 0.11854726
  0.65260806 0.1544332  0.59858186 0.38596031]]
np.row_stack((x,y))

array([[0.67022627, 0.25120792, 0.02617609, 0.51403094, 0.15839324,
        0.57900274, 0.01917046, 0.00688705, 0.74225908, 0.346025  ],
       [0.98799653, 0.98736352, 0.30693956, 0.35410828, 0.72678107,
        0.63816741, 0.64569699, 0.0029196 , 0.78463413, 0.01966627],
       [0.98799653, 0.98736352, 0.30693956, 0.35410828, 0.72678107,
        0.63816741, 0.64569699, 0.0029196 , 0.78463413, 0.01966627],
       [0.51550099, 0.10428722, 0.0297628 , 0.77017502, 0.53493682,
        0.11854726, 0.65260806, 0.1544332 , 0.59858186, 0.38596031]])

猜你喜欢

转载自blog.csdn.net/NockinOnHeavensDoor/article/details/84795678
tf
今日推荐