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

Tensorflow:如何以保持 2D 张量形状的方式使用 boolean_mask

Tensorflow:如何以保持 2D 张量形状的方式使用 boolean_mask

守候你守候我 2021-09-28 15:47:16
当我使用 tf.boolean_mask 时,结果是扁平化的。tensor7 = tf.constant( [[ 0,  1,  2,  3, -1],[ 2,  3,  4, -1, -1],[ 3,  6,  5,  4,  3]], tf.int64)mask7 = tf.constant([[ True,  True,  True,  True, False],  [ True,  True,  True, False, False], [ True,  True,  True,  True,  True]], tf.bool)result7=tf.boolean_mask(tensor7, mask7, axis=0)  with tf.Session() as sess:    print(sess.run([ result7 ]))数组([0, 1, 2, 3, 2, 3, 4, 3, 6, 5, 4, 3])]有没有办法使用它来保留原始的 3 数组形状?各个阵列的形状应该改变,因为它们现在更短了。我正在寻找这样的东西[数组([[ 0, 1, 2, 3 ], [ 2, 3, 4 ], [ 3, 6, 5, 4, 3]])
查看完整描述

1 回答

?
白猪掌柜的

TA贡献1893条经验 获得超10个赞

您的期望在逻辑上可能不合理,正如与您的问题类似的功能请求中进一步指出的那样。您需要为张量提供动态形状,这在 TensorFlow 中只有有限的支持(例如Ragged Tensors)。


查看完整回答
反对 回复 2021-09-28
  • 1 回答
  • 0 关注
  • 170 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号