If you just want to get the same value across the entire array, and you never want to change it, you can fool the step by making it equal to zero. That way, you just take the memory as one value. But you will get a numpy virtual array of any size and shape.
>>> import numpy as np >>> from numpy.lib import stride_tricks >>> arr = np.array([10]) >>> stride_tricks.as_strided(arr, (10, ), (0, )) array([10, 10, 10, 10, 10, 10, 10, 10, 10, 10])
But note that if you change any of the elements, all values ββin the array will be changed.
Senthil babu
source share