Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
09f6c39e
提交
09f6c39e
authored
9月 28, 2015
作者:
Xavier Bouthillier
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix stack(tensors, axis=0) documentation
上级
8a615a8d
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
73 行增加
和
13 行删除
+73
-13
basic.txt
doc/library/tensor/basic.txt
+41
-11
basic.py
theano/tensor/basic.py
+32
-2
没有找到文件。
doc/library/tensor/basic.txt
浏览文件 @
09f6c39e
...
@@ -703,30 +703,60 @@ Creating Tensor
...
@@ -703,30 +703,60 @@ Creating Tensor
except for the main diagonal, whose values are equal to one. The output
except for the main diagonal, whose values are equal to one. The output
will have same dtype as `x`.
will have same dtype as `x`.
.. function:: stack(tensors, axis=0)
.. function:: stack(tensors, axis=0)
Warning: The interface stack(*tensors) is deprecated!
Stack tensors in sequence on given axis (default is 0).
Return a Tensor representing for the arguments all stacked up into a single Tensor.
Take a sequence of tensors and stack them on given axis to make a single
(of 1 rank greater).
tensor. The size in dimension `axis` of the result will be equal to the number
of tensors passed.
:param tensors: a list or a tuple of one or more tensors of the same rank.
:param tensors: a list or a tuple of one or more tensors of the same rank.
:param axis: the axis along which the tensors will be stacked. Default value is 0.
:param axis: the axis along which the tensors will be stacked. Default value is 0.
:returns: A tensor such that rval[0] == tensors[0], rval[1] == tensors[1], etc.
:returns: A tensor such that rval[0] == tensors[0], rval[1] == tensors[1], etc.
>>> x0 = T.scalar()
Examples:
>>> x1 = T.scalar()
>>> x2 = T.scalar()
>>> a = theano.tensor.scalar()
>>> x = T.stack([x0, x1, x2])
>>> b = theano.tensor.scalar()
>>> c = theano.tensor.scalar()
>>> x = theano.tensor.stack([a, b, c])
>>> x.ndim # x is a vector of length 3.
>>> x.ndim # x is a vector of length 3.
1
1
>>> a = theano.tensor.tensor4d()
>>> b = theano.tensor.tensor4d()
>>> c = theano.tensor.tensor4d()
>>> x = theano.tensor.stack([a, b, c])
>>> x.ndim # x is a 5d tensor.
5
>>> rval = x.eval(dict((t, np.zeros((2, 2, 2, 2))) for t in [a, b, c]))
>>> rval.shape # 3 tensors are stacked on axis 0
(3, 2, 2, 2, 2)
We can also specify different axis than default value 0
>>> x = theano.tensor.stack([a, b, c], axis=3)
>>> x.ndim
5
>>> rval = x.eval(dict((t, np.zeros((2, 2, 2, 2))) for t in [a, b, c]))
>>> rval.shape # 3 tensors are stacked on axis 3
(2, 2, 2, 3, 2)
>>> x = theano.tensor.stack([a, b, c], axis=-2)
>>> x.ndim
5
>>> rval = x.eval(dict((t, np.zeros((2, 2, 2, 2))) for t in [a, b, c]))
>>> rval.shape # 3 tensors are stacked on axis -2
(2, 2, 2, 3, 2)
.. function:: stack(*tensors)
.. function:: stack(*tensors)
Return a Tensor representing for the arguments all stacked up into a single Tensor.
.. warning:: The interface stack(*tensors) is deprecated!
(of 1 rank greater).
Use stack(tensors, axis=0) instead.
Stack tensors in sequence vertically (row wise).
Take a sequence of tensors and stack them vertically to make a single
tensor.
:param tensors: one or more tensors of the same rank
:param tensors: one or more tensors of the same rank
:returns: A tensor such that rval[0] == tensors[0], rval[1] == tensors[1], etc.
:returns: A tensor such that rval[0] == tensors[0], rval[1] == tensors[1], etc.
...
...
theano/tensor/basic.py
浏览文件 @
09f6c39e
...
@@ -4024,9 +4024,10 @@ def shape_padaxis(t, axis):
...
@@ -4024,9 +4024,10 @@ def shape_padaxis(t, axis):
@constructor
@constructor
def
stack
(
*
tensors
,
**
kwargs
):
def
stack
(
*
tensors
,
**
kwargs
):
"""
Insert the arguments as slices into a tensor of 1 rank greater
.
"""
Stack tensors in sequence on given axis (default is 0)
.
The size in dimension `axis` of the result will be equal to the number
Take a sequence of tensors and stack them on given axis to make a single
tensor. The size in dimension `axis` of the result will be equal to the number
of tensors passed.
of tensors passed.
Note: The interface stack(*tensors) is deprecated, you should use
Note: The interface stack(*tensors) is deprecated, you should use
...
@@ -4039,6 +4040,35 @@ def stack(*tensors, **kwargs):
...
@@ -4039,6 +4040,35 @@ def stack(*tensors, **kwargs):
axis : int
axis : int
The index of the new axis. Default value is 0.
The index of the new axis. Default value is 0.
Examples
--------
>>> a = theano.tensor.scalar()
>>> b = theano.tensor.scalar()
>>> c = theano.tensor.scalar()
>>> x = theano.tensor.stack([a, b, c])
>>> x.ndim # x is a vector of length 3.
1
>>> a = theano.tensor.tensor4d()
>>> b = theano.tensor.tensor4d()
>>> c = theano.tensor.tensor4d()
>>> x = theano.tensor.stack([a, b, c])
>>> x.ndim # x is a 5d tensor.
5
>>> rval = x.eval(dict((t, np.zeros((2, 2, 2, 2))) for t in [a, b, c]))
>>> rval.shape # 3 tensors are stacked on axis 0
(3, 2, 2, 2, 2)
>>> x = theano.tensor.stack([a, b, c], axis=3)
>>> x.ndim
5
>>> rval = x.eval(dict((t, np.zeros((2, 2, 2, 2))) for t in [a, b, c]))
>>> rval.shape # 3 tensors are stacked on axis 3
(2, 2, 2, 3, 2)
>>> x = theano.tensor.stack([a, b, c], axis=-2)
>>> x.ndim
5
>>> rval = x.eval(dict((t, np.zeros((2, 2, 2, 2))) for t in [a, b, c]))
>>> rval.shape # 3 tensors are stacked on axis -2
(2, 2, 2, 3, 2)
"""
"""
# ---> Remove this when moving to the new interface:
# ---> Remove this when moving to the new interface:
if
not
tensors
and
not
kwargs
:
if
not
tensors
and
not
kwargs
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论