I am trying to create a fairly large array in python filled with zeros and ones. As a result, he should have about 1.2 billion. Records. I fill it, as in the example. The idea is that 400 entries are a time interval, and for each time interval there is a probability p that it is one. If so, it is filled with units for slot_duration time slots, otherwise it is filled with 400 inputs, one time slot, zeros.
import numpy as np
p = 0.01
slot_duration = 10
test_duration = 60
timeslots_left = test_duration * 1000 * 1000 / 20
transmission_array = []
while timeslots_left >= 0:
rand_num = np.random.choice((0, 1), p=[1 - p, p])
if rand_num == 1:
for i in range(0, slot_duration):
for j in range(0, 400):
transmission_array.append(1)
timeslots_left -= slot_duration
else:
for j in range(0, 400):
transmission_array.append(0)
timeslots_left -= 1
Performance is, of course, terrible. Within 10 seconds, it takes about 45 seconds to generate the array, but it also takes 45 seconds to iterate over.
: ? , , ? , ?
.