- lib.stride_tricks.as_strided(x, shape=None, strides=None, subok=False, writeable=True)#
Create a view into the array with the given shape and strides.
This function has to be used with extreme care, see notes.
Array to create a new.
- shapesequence of int, optional
The shape of the new array. Defaults to
- stridessequence of int, optional
The strides of the new array. Defaults to
- subokbool, optional
New in version 1.10.
If True, subclasses are preserved.
- writeablebool, 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).
as_stridedcreates a view into the array given the exact strides and shape. This means it manipulates the internal data structure of ndarray and, if done incorrectly, the array elements can point to invalid memory and can corrupt results or crash your program. It is advisable to always use the original
x.strideswhen calculating new strides to avoid reliance on a contiguous memory layout.
Furthermore, arrays created with this function often contain self overlapping memory, so that two elements are identical. Vectorized write operations on such arrays will typically be unpredictable. They may even give different results for small, large, or transposed arrays.
Since writing to these arrays has to be tested and done with great care, you may want to use
writeable=Falseto avoid accidental write operations.
For these reasons it is advisable to avoid