提取张量的跨步切片(广义 Python 数组索引)。
用法
tf.strided_slice(
input_, begin, end, strides=None, begin_mask=0, end_mask=0, ellipsis_mask=0,
new_axis_mask=0, shrink_axis_mask=0, var=None, name=None
)参数
-
input_一个Tensor。 -
begin一个int32或int64Tensor。 -
end一个int32或int64Tensor。 -
strides一个int32或int64Tensor。 -
begin_maskint32掩码。 -
end_maskint32掩码。 -
ellipsis_maskint32掩码。 -
new_axis_maskint32掩码。 -
shrink_axis_maskint32掩码。 -
varinput_或 None 对应的变量 -
name操作的名称(可选)。
返回
-
Tensor与input类型相同。
另见tf.slice。
大多数用户不想直接调用此操作,而是希望使用 NumPy-style 切片语法(例如 tensor[..., 3:4:-1, tf.newaxis, 3] ),该语法通过 tf.Tensor.getitem 和 tf.Variable.getitem 得到支持。此操作的接口是切片语法的低级编码。
粗略地说,这个操作从给定的 input_ 张量中提取了一个大小为 (end-begin)/stride 的切片。从 begin 指定的位置开始,切片通过将 stride 添加到索引继续,直到所有维度不小于 end 。请注意,步幅可以是负数,这会导致反向切片。
给定一个 Python 切片 input[spec0, spec1, ..., specn] ,该函数将按如下方式调用。
begin , end 和 strides 将是长度为 n 的向量。 n 通常不等于input_ 张量的秩。
在每个掩码字段 (begin_mask , end_mask , ellipsis_mask , new_axis_mask , shrink_axis_mask) 中,第 i 个位将对应于第 i 个规范。
如果设置了begin_mask 的第i 位,则忽略begin[i],并使用该维度中可能的最大范围。 end_mask 的工作方式类似,除了结束范围。
7x8x9 张量上的 foo[5:,:,:3] 等价于 foo[5:7,0:8,0:3] 。 foo[::-1] 反转形状为 8 的张量。
如果设置ellipsis_mask的第i位,则将根据需要在其他维度之间插入尽可能多的未指定维度。 ellipsis_mask 中只允许有一个非零位。
例如,形状 10x3x3x10 张量上的 foo[3:5,...,4:5] 等价于 foo[3:5,:,:,4:5] 并且 foo[3:5,...] 等价于 foo[3:5,:,:,:] 。
如果 new_axis_mask 的第 i 位被设置,则 begin , end 和 stride 将被忽略,并在输出张量的此时添加一个新的长度为 1 维。
例如,foo[:4, tf.newaxis,:2] 将产生形状 (4, 1, 2) 张量。
如果设置 shrink_axis_mask 的第 i 位,则意味着第 i 个规范将维度缩小 1,取索引 begin[i] 处的值。在这种情况下,end[i] 和 strides[i] 将被忽略。例如,在 Python 中,可能会执行 foo[:, 3,:],这将导致 shrink_axis_mask 等于 2。
注意:begin 和end 是zero-indexed。 strides 条目必须非零。
t = tf.constant([[[1, 1, 1], [2, 2, 2]],
[[3, 3, 3], [4, 4, 4]],
[[5, 5, 5], [6, 6, 6]]])
tf.strided_slice(t, [1, 0, 0], [2, 1, 3], [1, 1, 1]) # [[[3, 3, 3]]]
tf.strided_slice(t, [1, 0, 0], [2, 2, 3], [1, 1, 1]) # [[[3, 3, 3],
# [4, 4, 4]]]
tf.strided_slice(t, [1, -1, 0], [2, -3, 3], [1, -1, 1]) # [[[4, 4, 4],
# [3, 3, 3]]]
相关用法
- Python tf.strings.substr用法及代码示例
- Python tf.strings.reduce_join用法及代码示例
- Python tf.strings.regex_full_match用法及代码示例
- Python tf.strings.regex_replace用法及代码示例
- Python tf.strings.length用法及代码示例
- Python tf.strings.bytes_split用法及代码示例
- Python tf.strings.as_string用法及代码示例
- Python tf.strings.unsorted_segment_join用法及代码示例
- Python tf.strings.lower用法及代码示例
- Python tf.strings.split用法及代码示例
- Python tf.strings.upper用法及代码示例
- Python tf.strings.unicode_decode_with_offsets用法及代码示例
- Python tf.strings.join用法及代码示例
- Python tf.strings.to_hash_bucket用法及代码示例
- Python tf.strings.ngrams用法及代码示例
- Python tf.strings.to_hash_bucket_strong用法及代码示例
- Python tf.strings.unicode_decode用法及代码示例
- Python tf.strings.unicode_encode用法及代码示例
- Python tf.strings.format用法及代码示例
- Python tf.strings.to_hash_bucket_fast用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.strided_slice。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
