Arr#
- class Arr(name=None, dtype=None, default=None, nan=None, label=None, skip_init=False, people=None)[source]#
Bases:
BaseArr
Store a state of the agents (e.g. age, infection status, etc.) as an array.
In practice,
Arr
objects can be used interchangeably with NumPy arrays. They have two main data interfaces:Arr.raw
contains the “raw”, underlying NumPy array of the data.Arr.values
contains the “active” values, which usually corresponds to agents who are alive.By default, operations are performed on active agents only (specified by
Arr.auids
, which is a pointer tosim.people.auids
). For example,sim.people.age.mean()
will only use the ages of active agents. Thus,sim.people.age.mean()
is equal tosim.people.age.values.mean()
, notsim.people.age.raw.mean()
.If indexing by an int or slice,
Arr.values
is used. If indexing by anss.uids
object,Arr.raw
is used.Arr
objects can’t be directly indexed by a list or array of ints, as this would be ambiguous about whethervalues
orraw
is intended. For example, if there are 1000 people in a simulation and 100 of them have died,sim.people.age[999]
will return anIndexError
(sincesim.people.age[899]
is the last active agent), whereassim.people.age[ss.uids(999)]
is valid.- Parameters:
name (str) – The name for the state (also used as the dictionary key, so should not have spaces etc.)
dtype (- A scalar with the same) – The dtype to use for this instance (if None, infer from value)
default (any) – Specify default value for new agents. This can be
dtype
callable (- A)
produce (with a single argument for the number of values to)
instance (- A ss.Dist)
nan (any) – the value to use to represent NaN (not a number); also used as the default value if not supplied
label (str) – The human-readable name for the state
skip_init (bool) – Whether to skip initialization with the People object (used for uid and slot states)
people (ss.People) – Optionally specify an initialized People object, used to construct temporary Arr instances
Attributes
Link to the indices of active agents -- sim.people.auids
isnan
notnan
Return the values of the active agents
Methods
- property auids#
Link to the indices of active agents – sim.people.auids
- property values#
Return the values of the active agents
- grow(new_uids=None, new_vals=None)[source]#
Add new agents to an Arr
This method is normally only called via People.grow().
- Parameters:
new_uids – Numpy array of UIDs for the new agents being added
new_vals – If provided, assign these state values to the new UIDs
- init_vals()[source]#
Actually populate the initial values and mark as initialized; only to be used on initialization