<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def nb_persons(self, role = None):
 """ Returns the number of persons contained in the entity. If ``role`` is provided, only the entity member with the given role are taken into account. """

        if role:
            if role.subroles:
                role_condition = np.logical_or.reduce([self.members_role == subrole for subrole in role.subroles])
            else:
                role_condition = self.members_role == role
            return self.sum(role_condition)
        else:
            return np.bincount(self.members_entity_id)