操纵张量流和/或theano中的步幅

时间:2017-03-27 09:57:27

标签: python numpy tensorflow theano

在numpy中,你可以通过改变数组的形状和步幅来欺骗在滑动窗口上应用的方法,例如:

import numpy

x = numpy.arange(20)
r=5

y = numpy.ndarray(
    buffer=x.data,
    shape=(x.shape[0] - r + 1, r),
    strides=(x.itemsize, x.itemsize),
    dtype=x.dtype
)
print(x)
print(y)
x[4] = -1
print(x)
print(y)

https://ideone.com/SjdtrB

输出:

[0 1 2 3 4 5 6]
[[0 1 2 3 4]
 [1 2 3 4 5]
 [2 3 4 5 6]]
[ 0  1  2  3 -1  5  6]
[[ 0  1  2  3 -1]
 [ 1  2  3 -1  5]
 [ 2  3 -1  5  6]]

这样可以节省内存,而且计算时间也是不变的。

这在tensorflow或theano中也有可能吗?这些框架中的任何一个都在其内部表示中使用了跨步吗?

0 个答案:

没有答案