04-26-2017 09:57 AM
How can I create matrix like this:
1 2 3 . . . .n-2 n-1 n
2 1 2 . . ..n-3 n-2 n-1
3 2 1 . . . .n-4 n-3 n-2
.........................................................
n-1 n-2 n-3 .....2 1 2
n n-1 n-2 3 2 1
04-26-2017 11:29 AM
I hate to do homework, if that's what this is. What have you tried? My solution uses two For Loops inside one For Loop, with one of the inner ones making the countdown from the left and the other making the count-up part.
04-26-2017 11:40 AM
I would probably first create a V shaped 1D array going [N, N-1, ... 2, 1, 2, ..., N--1, N], then use a single FOR loop to subset into it with an index based on [I] and fixed length, then autoindex at the output tunnel.
04-26-2017 12:16 PM - edited 04-26-2017 12:18 PM
Ramp 1..N. Loop and replace index 0 on each iteration, rotate array in feedback, and index output.
04-26-2017 12:57 PM - edited 04-26-2017 01:06 PM
04-26-2017 01:13 PM - edited 04-26-2017 01:15 PM
@altenbach That's pretty cool. Super fast, too. I've noticed that rotating arrays is not particularly fast, so this is much better. I'm not sure there is much time difference between the absolute and increment operations inside vs outside the loop.
04-26-2017 01:23 PM - edited 04-26-2017 01:24 PM
@Mancho00 wrote:
I'm not sure there is much time difference between the absolute and increment operations inside vs outside the loop.
I initially had it inside the inner loop, but identical operations on arrays can potentially utilize SSE instructions for an overall gain by at least a factor of 2, but I am not sure if the compiler would utilize it here. In any case these array operations operate in place, so there should be very little difference. It is even possible that the compiler would generate identical code for the two versions (inside vs. outside) once all internal optimizations are applied. 😄
(make sure to disable debugging when benchmarking).
04-26-2017 01:36 PM - edited 04-26-2017 01:39 PM
04-26-2017 01:41 PM
@altenbach wrote:
These might scale even better, no inner loop! 😄
Now you're just showing off.
04-27-2017 05:11 AM
Thanks/ I did it with formula node.