最近看代码的时候看到了这么一个函数
np.stride_tricks.as_strided(x, shap, strides, subok, writeable)
Parameters:
x : ndarray
Array to create a new.
shape : sequence of int, optional
The shape of the new array. Defaults to x.shape.
strides : sequence of int, optional
The strides of the new array. Defaults to x.strides.
subok : bool, optional
New in version 1.10.
If True, subclasses are preserved.
writeable : bool, optional
New in version 1.12.
If set to False, the returned array will always be readonly. Otherwise it will be writable if the original array was. It is advisable to set this to False if possible (see Notes).
Returns:
view : ndarray
看个实际案例便可以明白如何使用:
# 来源:NumPy Cookbook 2e Ch2.9
import numpy as np
# 数独是个 9x9 的二维数组
# 包含 9 个 3x3 的九宫格
sudoku = np.array