blocks.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:fold 作者: tensorflow 项目源码 文件源码
def Slice(*args, **kwargs):  # pylint: disable=invalid-name
  """A block which applies Python slicing to a PyObject, Tuple, or Sequence.

  For example, to reverse a sequence:
  ```python
  (Map(Scalar()) >> Slice(step=-1)).eval(range(5)) => [4, 3, 2, 1, 0]

Positional arguments are not accepted in order to avoid the ambiguity of slice(start=N) vs. slice(stop=N).

Args: *args: Positional arguments; must be empty (see above). **kwargs: Keyword arguments; start=None, stop=None, step=None, name=None.

Returns: The block. """ if args: raise TypeError('Slice does not accept positional arguments; allowed ' 'keyword arguments are start, stop, and step') name = kwargs.pop('name', None) return GetItem(_get_slice(**kwargs), name=name).set_constructor_name( 'td.Slice') ```

评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号