【发布时间】:2016-08-07 18:37:14
【问题描述】:
import random
#import matplotlib.pyplot as plt
a1 = ['','','?','']
a2 = [10,25,43.34,90]
i = 0
i_array = []
while i < 10:
i_array.append(i)
i = i + 1
r = random.random()
for i, j in enumerate(a1):
if j == '?':
print(a2[i]*r)
a3 = a2[i]*r
plt.line(r,a3)
我在 a1 中的问号可能在这四个位置中的任何位置。因此,a2 中对应的值需要更改。 答案: 随机导入 #import matplotlib.pyplot as plt
a1 = ['','','?','']
a2 = [10,25,43.34,90]
xarray=[]
yarray=[]
i = 0
i_array = []#probably can delete this, I don't see any reason for it
for i in range(0,10):#use a for loop instead
i_array.append(i)
r = random.random()
a3 = a2[a1.index('?')]*r#index here instead of the for loop
print(a3)#since your assigning a3 anyway, might as well print that
xarray.append(r)#plot needs arrays
yarray.append(a3)
plt.plot(xarray,yarray)#plot your arrays
【问题讨论】:
标签: python arrays random matplotlib distribution