Is it possible to reverse an array using as_strided
in NumPy? I tried the following and got garbage results
Note : I am aware of indexing tricks like ::-1, but what to know if this can be achieved thru ax_strided.
import numpy as np
from numpy.lib.stride_tricks import as_strided
elems = 16
inp_arr = np.arange(elems).astype(np.int8)
print(inp_arr)
print(inp_arr.shape)
print(inp_arr.strides)
expanded_input = as_strided(inp_arr[15],
shape = inp_arr.shape,
strides = (-1,))
print(expanded_input)
print(expanded_input.shape)
print(expanded_input.strides)
Output
[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15]
(16,)
(1,)
[ 15 -113 0 21 -4 -119 -53 3 79 0 0 0 0 0
0 2]
(16,)
(-1,)