提问人:CA Khan 提问时间:9/13/2022 最后编辑:CA Khan 更新时间:9/13/2022 访问量:152
从张量张量流中删除数据 /indices 值(范围)
Removal of data /indices values(range) from a tensor tensorflow
问:
请考虑以下张量
params = tf.constant([
1.3, 7, 1, 0.5, -2,
3, -0.033, 0.9, -6.3, 4.1,
9, 5, 0.25, -6, 0.2])
params
上述张量的输出为
<tf.Tensor: shape=(15,), dtype=float32, numpy=
array([ 1.3 , 7. , 1. , 0.5 , -2. , 3. , -0.033, 0.9 ,
-6.3 , 4.1 , 9. , 5. , 0.25 , -6. , 0.2 ],
dtype=float32)>
现在我想删除,假设第一个值,即 1.3,从索引中删除从 4 到 6 的值,从值 0.25 开始的值 [12:] 输出应为
<tf.Tensor: shape=(8,), dtype=float32, numpy=
array([ 7. , 1. , 0.5 , 0.9 ,
-6.3 , 4.1 , 9. , 5.],
dtype=float32)>
能做到吗? 提前致谢
答:
1赞
ClaudiaR
9/13/2022
#1
当然,看看张量切片。在你的情况下,它将是:
import tensorflow as tf
params = tf.constant([
1.3, 7, 1, 0.5, -2,
3, -0.033, 0.9, -6.3, 4.1,
9, 5, 0.25, -6, 0.2])
out = tf.concat([params[1:4], params[7:12]], 0)
print(out)
输出:
tf.Tensor([ 7. 1. 0.5 0.9 -6.3 4.1 9. 5. ], shape=(8,), dtype=float32)
评论