vendredi 26 octobre 2018

Make matrix of random integers [duplicate]

This question already has an answer here:

I need to write a function that takes the number of rows and columns and returns a matrix of a size rows × columns filled with random values between -10,10.

**need to be done without NumPy, Pandas and etc.

I write:

Mat = []

def mf(r,c):
    for i in range (0,c):
        Mat.append([])
    for i in range (0,r):
        for j in range (0,c):
            Mat[i].append(j)
            Mat[i][j]=0

    print(Mat)
mf(3,4)

How to insert random values in the range -10,10?

Any help, tips or solutions are greatly appreciated, I am a python beginner with a very basic knowledge.

Many thanks in advance!




Aucun commentaire:

Enregistrer un commentaire