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 to sim.people.auids). For example, sim.people.age.mean() will only use the ages of active agents. Thus, sim.people.age.mean() is equal to sim.people.age.values.mean(), not sim.people.age.raw.mean().

If indexing by an int or slice, Arr.values is used. If indexing by an ss.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 whether values or raw is intended. For example, if there are 1000 people in a simulation and 100 of them have died, sim.people.age[999] will return an IndexError (since sim.people.age[899] is the last active agent), whereas sim.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

auids

Link to the indices of active agents -- sim.people.auids

isnan

notnan

values

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

set(uids, new_vals=None)[source]#

Set the values for the specified UIDs

set_nan(uids)[source]#

Shortcut function to set values to NaN

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

Link a People object to this state, for access auids

init_vals()[source]#

Actually populate the initial values and mark as initialized; only to be used on initialization

asnew(arr=None, cls=None, name=None)[source]#

Duplicate and copy (rather than link) data, optionally resetting the array

true()[source]#

Efficiently convert truthy values to UIDs

false()[source]#

Reverse of true(); return UIDs of falsy values

to_json()[source]#

Export to JSON