dimanche 13 décembre 2020

How do I create a randomly generated matrix with randomly generated dimension and then transpose it?

This is what I have so far:

import random
import numpy as np
r1 = random.randint(0, 100)
r2 = random.randint(0, 100)
r3 = random.randint(0, 100)
if r2 < r1:
    print("invalid")
elif r2 < r3:
    print("invalid")
a = np.arange(r2).reshape((r1, r3))
print(a)
print(a.transpose())

basically, I created 3 variables with random numbers in a arange from 1 to 100, and I think I misued the if/else statement and also messed up the np.arange().reshape() part of the program. Any help would be appreciated.




Aucun commentaire:

Enregistrer un commentaire