python - 如何从张量流中的张量中删除特定值的向量?
问题描述
我想实现以下操作。给定一个张量,
m = ([[1, 1, 1], [2, 2, 2], [3, 3, 3]])
如何实现从 m 中删除值为 [2, 2, 2] 的向量?
解决方案
你可以这样做:
import tensorflow as tf
def remove_row(m, q):
# Assumes m is 2D
mask = tf.math.reduce_any(tf.not_equal(m, q), axis=-1)
return tf.boolean_mask(m, mask)
# Test
m = tf.constant([[1, 1, 1], [2, 2, 2], [3, 3, 3]])
q = tf.constant([2, 2, 2])
tf.print(remove_row(m, q))
# [[1 1 1]
# [3 3 3]]
推荐阅读
- asp.net - 在页面加载上调用函数 LordRecord() 不会更新按钮单击 ASP.NET 上的数据
- hdf5 - 访问 HDF5 文件中的 Fletcher-32 校验和
- html - 向右滚动时如何防止元素移动?
- rust - Rust:返回对字符串的引用时的意外行为
- python - 使用 Networkx 可视化大图
- jq - AWS CLI 和 jq:使用 ecs list-tasks 获取任务 ID 时出错
- django - django rest框架流程
- android - 如何在 HMS 游戏服务中添加 3d 视图
- r - 通过r中的循环复制数据
- linux - ffprobe 报告一些错误的元数据,但仅在输入管道输入时