title: python - running for 5000 loops without error to obtain sample distribution of sample median
body: <p>How do I repeat this code 5000 times? Can't seem to make it work. How can I do this without running a loop?</p>
  
  <pre><code>age = ['&lt;=20', '21-30', '31-40', '41-50', '51-60', '61-65', '&gt;=66']
  number_of_people = np.array([105770, 1170176, 1797410, 1256255, 692903, 88260, 7362])
  mean_salary = np.array([17487, 32481, 47044, 56863, 59514, 76572, 114779])
  sd = np.array([7459, 18207, 37225, 65919, 103232, 137916, 360839])
  total_population = 5118136
  samplesize = 200
  
  sample200 = [(num/total_population) * samplesize for num in number_of_people]
  sample200 = np.round(sample200)
  #Adding one person to age group of '&gt;=66' for sample size of 200
  newsample200 = [4, 46, 70 , 49, 27, 3, 1]
  
  
  sample200dist = np.array([])
  
  for i in range(len(newsample200)):
      for j in range(newsample200[i]):
          new_dist = np.random.normal(mean_salary[i], sd[i])
          if new_dist &gt; 0.0:
              sample200dist = np.append(sample200dist, new_dist)
          else:
              sample200dist = np.append(sample200dist, abs(new_dist))
  
  print('The median monthly salary of sample size 200 is:', np.median(sample200dist))
  </code></pre>