提交 7c53798c authored 作者: Frederic's avatar Frederic

Added stacklist from gh-1335 in the doc of Theano.

The dostring of the file tensor/basic.py isn't automatically included in the theano doc as others module as it don't display nicely. So we do it in a better format manually.
上级 1e146ec7
......@@ -646,6 +646,35 @@ dimensions, see :meth:`_tensor_py_operators.dimshuffle`.
>>> x = T.concatenate([x0, x1[0], T.shape_padright(x2)], axis=1)
>>> # x.ndim == 2
.. function:: stacklist(tensor_list)
:type tensor_list: an iterable that contain tensors or iterable
with at the end tensors.
:param tensor_list: tensors to be
stackend together.
Recursivly stack lists of tensors to maintain similar structure.
This function can create a tensor from a shaped list of scalars
>>> from theano.tensor import stacklists, scalar, matrix
>>> from theano import function
>>> a,b,c,d = map(scalar, 'abcd')
>>> X = stacklists([[a, b], [c, d]])
>>> f = function([a, b, c, d], X)
>>> f(1, 2, 3, 4)
>>> # array([[ 1., 2.], [ 3., 4.]], dtype=float32)
We can also stack arbitrarily shaped tensors. Here we stack matrices into
a 2 by 2 grid.
>>> from numpy import ones
>>> a,b,c,d, = [tensor.matrix(a) for a in 'abcd']
>>> X = stacklists([[a, b], [c, d]])
>>> f = function([a, b, c, d], X)
>>> x = ones((4, 4), 'float32')
>>> f(x, x, x, x).shape
>>> # (2, 2, 4, 4)
Reductions
==========
......
......@@ -8241,8 +8241,7 @@ def stacklists(arg):
>>> from theano.tensor import stacklists, scalar, matrix
>>> from theano import function
>>> a,b,c,d = map(scalar, 'abcd')
>>> X = stacklists([[a, b],
... [c, d]])
>>> X = stacklists([[a, b], [c, d]])
>>> f = function([a, b, c, d], X)
>>> f(1, 2, 3, 4)
array([[ 1., 2.],
......@@ -8252,8 +8251,7 @@ def stacklists(arg):
a 2 by 2 grid.
>>> from numpy import ones
>>> a,b,c,d, = [tensor.matrix(a) for a in 'abcd']
>>> X = stacklists([[a, b],
... [c, d]])
>>> X = stacklists([[a, b], [c, d]])
>>> f = function([a, b, c, d], X)
>>> x = ones((4, 4), 'float32')
>>> f(x, x, x, x).shape
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论