Population.allocate

Population.allocate

Population.allocate(length)[source]

Allocate the internal data array for assignment of objects.

Warning: This removes all internal data.

Example:

Create a population with two objects. Here the load_data function is a fictional function that creates a row with the needed data.

from population import Population
from my_data_loader import load_data

my_pop = Population(
    name='two objects',
    extra_columns = ['m', 'color'],
    dtypes = ['Float64', 'U20'],
    space_object_uses = [True, False],
)

print(len(my_pop)) #will output 0
my_pop.allocate(2)
print(len(my_pop)) #will output 2

my_pop.data[0] = load_data('obj1')
my_pop.data[1] = load_data('obj2')