python - tensorflow - 如何选择数组中除索引序列之外的所有元素?
问题描述
可以使用此处np.delete
指定的方式完成等效的 numpy 操作。由于没有,我不确定如何在.tf.delete
tensorflow
解决方案
我想你可能想使用 tf.boolean_mask。例如,
labels = tf.Variable([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
a = tf.Variable([1, 0, 0])
a1 = tf.cast(a, dtype=tf.bool)
print(a1)
mask = tf.math.logical_not(a1)
print(mask)
print(tf.boolean_mask(labels, mask))
输出是,
tf.Tensor([ True False False], shape=(3,), dtype=bool)
tf.Tensor([False True True], shape=(3,), dtype=bool)
tf.Tensor(
[[0 1 0]
[0 0 1]], shape=(2, 3), dtype=int32)
因此,您可以定义一个掩码来删除一维张量的特定向量。
推荐阅读
- python - Grad-CAM算法的实现
- java - 我的 Java 删除方法有问题
- javascript - 多次链 setState
- android - 使用 Kotlin 和 SQLite 在 Android X 中制作一个简单的可点击列表(Android Studio 4.1)
- python - 如何使用 pyppeteer 在新标签页中打开 url?
- python - Python中的不确定性包:使用给定的协方差矩阵来获取数据的不确定性
- javascript - 冒泡对组件的 HTTP 发布响应
- php - 如何防止 Firefox >80 缓存重定向目标页面?
- flutter - 在 null 上调用了 getter 'stream'
- xpath - Google 工作表上的 ImportXML 函数,用于获取 GitHub 上最后一次提交的日期