4
$\begingroup$

I have a listo of 1000 numbers $\{x_0,x_1,\cdots,x_{999}\}$, I need to fill a matrix with these numbers. The matrix must have this form:

$$\left( \begin{array}{cccc} x_{9} &x_8 &\cdots& x_0 \\ x_{10} &x_9 &\cdots &x_1 \\ \dots & \cdots& \cdots &\cdots\\ x_{999} &x_{998} & \cdots& x_{990} \end{array}\right)$$

I have tried with

k = 0;
line = {};
mat = {};
Do[
 Do[AppendTo[line, x[[k + i]]], {i, 10}];
 AppendTo[mat, line];
 k = k + 1;, {j, 10}]

but it is wrong

$\endgroup$
3
$\begingroup$

This will do it:

Reverse /@ Partition[Range[0, 999], 10, 1]

{{9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, ... {999, 998, 997, 996, 995, 994, 993, 992, 991, 990}}

Replace Range[0, 999] by your x.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.