提交 9eecfab3 authored 作者: James Bergstra's avatar James Bergstra

added shape_padright, and renamed leftpad_shape -> shape_padleft

上级 b2830444
...@@ -1559,11 +1559,24 @@ def join(axis, *tensors): ...@@ -1559,11 +1559,24 @@ def join(axis, *tensors):
""" """
@constructor @constructor
def leftpad_shape(tensor, n_ones): def shape_padleft(tensor, n_ones):
"""Reshape `tensor` by left-padding the shape with `n_ones` 1s""" """Reshape `tensor` by left-padding the shape with `n_ones` 1s
See also: `shape_padright` and `Dimshuffle`
"""
pattern = ['x']*n_ones + [i for i in range(tensor.type.ndim)] pattern = ['x']*n_ones + [i for i in range(tensor.type.ndim)]
return DimShuffle(tensor.broadcastable, pattern)(tensor) return DimShuffle(tensor.broadcastable, pattern)(tensor)
@constructor
def shape_padright(tensor, n_ones):
"""Reshape `tensor` by right-padding the shape with `n_ones` 1s
See also: `shape_padleft` and `Dimshuffle`
"""
pattern = [i for i in range(tensor.type.ndim)] + ['x']*n_ones
return DimShuffle(tensor.broadcastable, pattern)(tensor)
@constructor @constructor
def stack(*tensors): def stack(*tensors):
"""Insert the arguments as slices into a tensor of 1 rank greater. """Insert the arguments as slices into a tensor of 1 rank greater.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论