用途:按照shape和strides划分x
shape:新矩阵的维度
strides:numpy数组的属性,跨越数组各个维度所需要经过的字节数(bytes)
后两个参数不做介绍
重点在strides:
1. strides = (12,3)
[[0 1 2] [3 4 5] [6 7 8]]
2. strides = (12,4,12,4)
[[0 1 2] [3 4 5] [6 7 8]] -------> [[[[0 1] [3 4]] [[1 2] [4 5]]] [[[3 4] [6 7]] [[4 5] [7 8]]]]
e.g.
code:
Z = np.arange(1,15,dtype=np.uint32) R = np.lib.stride_tricks.as_strided(Z,(11,4),(4,4)) print(R)
out:
[[ 1 2 3 4] [ 2 3 4 5] [ 3 4 5 6] [ 4 5 6 7] [ 5 6 7 8] [ 6 7 8 9] [ 7 8 9 10] [ 8 9 10 11] [ 9 10 11 12] [10 11 12 13] [11 12 13 14]]