I am trying to make a matrix from a single column of values. Could you please give me an easy way to make it? Thanks in advance. The first column is the original data. Here it goes. I want the yellow colored matrix
Asked
Active
Viewed 39 times
-1
-
Please provide the code you have tried/have so far. For asking great questions and therefore getting useful answers please refer to this article: https://stackoverflow.com/help/how-to-ask And also look around the help center for further info. – Andrew Adam Nov 16 '17 at 10:05
-
Use [this](https://stackoverflow.com/questions/45960192/using-numpy-as-strided-function-to-create-patches-tiles-rolling-or-sliding-w) and do `window_nd(arr, 5)[:,::-1]` – Daniel F Nov 16 '17 at 10:23
-
Thanks Daniel :) worked like a charm. Did not know what to use as search words for my question. – Mahmud Sabbir Nov 17 '17 at 11:12
1 Answers
0
Seems the images you provided earlier are now gone. If I remember them correctly you could try the following code.
import numpy as np
i = [1,2,3,4,5]
i.reverse()
result=np.array([[g+x for g in i] for x in range(5)])

Rasmus Lyngdal-Christensen
- 216
- 2
- 9