How to create a spiral matrix in numpy python?

Viewed 159

Output should be n rows * n cols with numbers from n to n ** 2 (for example 5 to 25) in a spiral starting from the upper left corner and twisted clockwise, as shown in the example (here n=5):

Sample input 5

######################

Sample Output:

1 2 3 4 5

16 17 18 19 6

15 24 25 20 7

14 23 22 21 8

13 12 11 10 9

0 Answers
Related