Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

This code gives 2D arrays but I need multiple 1-dimensional arrays with random numbers.

a,b,c,d,e=[],[],[],[],[]
for i in (a,b,c,d,e):
     j=np.random.randint(0,15,size=7)
     i.append(j)
print(a,b,c,d,e)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
228 views
Welcome To Ask or Share your Answers For Others

1 Answer

You append numpy array to a list, so you got 2D. Try this

import numpy as np

a, b, c, d, e = (np.random.randint(0,15,size=7) for i in range(5))
print(a,b,c,d,e)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...