Home > Blockchain >  How can I generate a 2D matrix of natural numbers wth zero in ascending order in shell script or ano
How can I generate a 2D matrix of natural numbers wth zero in ascending order in shell script or ano

Time:01-12

I need to generate matrices of natural numbers in ascending order with zero (0), but they are very large ones and it will be hard to write them by hand.

What I want is to generate matrices like this:

0   1   2   3
4   5   6   7
8   9   10  11
12  13  14  15

How can I do that in shell script or another programming language.

CodePudding user response:

In python:

print('\n'.join([' '.join([str(x*n y) for y in range(0,k)]) for x in range(0,n)]))

Well, you might want to use tabulate or something to keep it aligned..

  •  Tags:  
  • Related