arrays
Classes
| Name | Description |
|---|---|
| TwoDimensionalArr | A State that tracks a two-dimensional array of values, indexed by UIDs. Because this is a true State, it is linked to |
TwoDimensionalArr
arrays.TwoDimensionalArr(
name=None,
dtype=None,
default=None,
nan=None,
label=None,
skip_init=False,
people=None,
ncols=1,
)A State that tracks a two-dimensional array of values, indexed by UIDs. Because this is a true State, it is linked to People and can grow dynamically as new agents are added. It is used for storing state that has multiple columns, such as the ages at which a child is born.
It can be indexed by UIDs, slices, or boolean arrays, and supports setting values for new agents.
example usage: self[uid]: returns the entire row of values for the specified uid self[uid, col]: returns the value in the specified column for the specified uid self[slice]: returns all rows for the specified slice self[bool_arr]: returns all rows where the boolean array is True
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| name | str | Name of the array | None |
| dtype | type | Data type of the array (e.g., np.float64) | None |
| default | Default value to use when setting new agents | None |
|
| nan | Value to use for NaN entries | None |
|
| label | str | Label for the array, used in plots and reports | None |
| skip_init | bool | If True, do not initialize the array; useful for module state definitions | False |
Attributes
| Name | Description |
|---|---|
| values | Return the values of the active agents |
Methods
| Name | Description |
|---|---|
| grow | Add new agents to an Arr |
| set | Set the values for the specified UIDs |
grow
arrays.TwoDimensionalArr.grow(new_uids=None, new_vals=None)Add new agents to an Arr
This method is normally only called via People.grow().
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| new_uids | Numpy array of UIDs for the new agents being added | None |
|
| new_vals | If provided, assign these state values to the new UIDs | None |
set
arrays.TwoDimensionalArr.set(uids, new_vals=None)Set the values for the specified UIDs