I am trying to create a random square matrix of nxn random numbers with numpy. Of course I am able to generate enough random numbers but I am having trouble using numpy to create a matrix of variable length. This is as far as I have gotten thus far:
def testMatrix(size):
a = []
for i in range(0, size*size):
a.append(randint(0, 5))
How can I put this list into an array of size x size?
Try
np.random.randint(0, 5, size=(s, s))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With