作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个示例代码要运行:
import numpy a np
import tensorflow as tf
import tensorflow.contrib.eager as tfe
tfe.enable_eager_execution()
x = np.random.randint(100,size=(4,4))
indexes =tf.sequence_mask([1,2,2,4],4)
"""
indexes = [
[True,False,False,False],
[True,True,False,False],
[True,True,False,False],
[True,True,True,True],
]
"""
y = tf.boolean_mask(x,indexes)
# y = array([43, 78, 68, 54, 46, 28, 15, 52, 3])
[batch_size, max_time, feature_length]
我会把它切成这样:
indexes = tf.sequence_mask([x_1, x_2, x_3, ..., x_batch_size], max_time)
最佳答案
这可能有效-
x = tf.constant([[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]])
indexes = tf.sequence_mask([1, 2, 2, 4], 4)
y = tf.multiply(x, tf.cast(indexes, x.dtype))
-> y is [[ 1 0 0 0]
[ 5 6 0 0]
[ 9 10 0 0]
[13 14 15 16]]
关于python - 不减少尺寸的 Tensorflow 序列掩码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49477417/
我是一名优秀的程序员,十分优秀!