为了账号安全,请及时绑定邮箱和手机立即绑定

如何在 TensorFlow 中对非本地方法中的方法本地张量进行就地更改?

如何在 TensorFlow 中对非本地方法中的方法本地张量进行就地更改?

慕雪6442864 2021-09-24 16:52:03
我们知道在python中,数据是按名称跨方法传递的。假设我有一个列表a,它是方法 m1() 的本地列表,我想将它传递给另一个方法并在其他方法中对其进行一些更改并保留这些更改,然后它非常简单并且可以如下进行:def m1(a):   a.append(5)def m2():   a = [1, 2, 3, 4]   print('Before: ', a) # Output= Before: [1, 2, 3, 4]   m1(a)   print('After: ', a) # Output= After: [1, 2, 3, 4, 5]m2()如果a是张量,如何做同样的事情?我想做类似的事情def m1(t1):  t2 = tf.constant([[[7, 4], [8, 4]], [[2, 10], [15, 11]]])  tf.concat([t1, t2], axis = -1)def m2():  t1 = tf.constant([[[1, 2], [2, 3]], [[4, 4], [5, 3]]])  se = tf.Session()  print('Before: ', se.run(t1)) # Output = Before: [[[1, 2], [2, 3]], [[4, 4], [5, 3]]]  m1(t1)  print('After: ', se.run(t1))  #Actual Output = After : [[[1, 2], [2, 3]], [[4, 4], [5, 3]]] | Desired Output = After : [[[1, 2, 7, 4], [2, 3, 8, 4]], [[4, 4, 2, 10], [5, 3, 15, 11]]]m2()
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 152 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信