Let's suppose i have this array:
import numpy as np
x = np.arange(4)
array([0, 1, 2, 3])
I want to write a very basic formula which will generate from x this array:
array([[0, 1, 2, 3],
[1, 2, 3, 4],
[2, 3, 4, 5],
[3, 4, 5, 6]])
What is the shortest way to do that with python and numpy ?
Thanks
x[None, :] + x[:, None]Which is probably a dupe of something else, simple as it is.stepsize=1solves, it, doesn't it?xarray he specified. There are no4,5,6elements to stride to usingstride_tricks