How to create a random matrix?

前端 未结 2 1823
执念已碎
执念已碎 2021-01-27 10:44

I want create a random matrix like [[[100, 50, 25], [22, 75, 195]]]

My code is

n = 1
r = 2
e = 3

sup = []

for i in range(n):
    sup1 = []
    for c         


        
2条回答
  •  走了就别回头了
    2021-01-27 10:56

    You can use numpy to directly get the random matrix of desired size with values in a given range.

    >>> numpy.random.randint(low = 0, high = 200, size=(2, 4))
    array([[ 75,  21, 132,  90],
           [112,  11, 104, 114]])
    
    >>> r = 2
    >>> n = 1
    >>> numpy.random.randint(low = 0, high = 200, size=(r, n))
    array([[94],
           [51]])
    

    More details

提交回复
热议问题