numpy 1.22.4 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef
as_strided(x, shape=None, strides=None, subok=False, writeable=True)
warning

Notes

as_strided creates 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.strides when 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=False to avoid accidental write operations.

For these reasons it is advisable to avoid as_strided when possible.

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
versionadded

If True, subclasses are preserved.

writeable : bool, optional
versionadded

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

Create a view into the array with the given shape and strides.

See Also

broadcast_to

broadcast an array to a given shape.

lib.stride_tricks.sliding_window_view

userfriendly and safe function for the creation of sliding window views.

reshape

reshape an array.

Examples

See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

numpy.lib.stride_tricks.sliding_window_view

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /numpy/lib/stride_tricks.py#38
type: <class 'function'>
Commit: