Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Create matrix 100×100 each row with next ordinal number

I try to create a matrix 100×100 which should have in each row next ordinal number like below:
enter image description here

I created a vector from 1 to 100 and then using for loop I copied this vector 100 times. I received an array with correct data so I tried to sort arrays using np.argsort, but it didn’t worked as I want (I don’t know even why there are zeros in after sorting).

Is there any option to get this matrix using another functions? I tried many approaches, but the final layout was not what I expected.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

max_x = 101
    
z = np.arange(1,101)
print(z)

x = []

for i in range(1,max_x):
    x.append(z.copy())

print(x)

y = np.argsort(x)
y

>Solution :

argsort returns the indices to sort by, that’s why you get zeros. You don’t need that, what you want is to transpose the array.

Make x a numpy array and use T

y = np.array(x).T

Output

[[  1   1   1 ...   1   1   1]
 [  2   2   2 ...   2   2   2]
 [  3   3   3 ...   3   3   3]
 ...
 [ 98  98  98 ...  98  98  98]
 [ 99  99  99 ...  99  99  99]
 [100 100 100 ... 100 100 100]]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading