<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def calls_sorted(self):
 """ calls sorted in z """

        def _z(call):
            if isinstance(call.z.value, np.ndarray):
                return np.mean(call.z.value.flatten())
            elif isinstance(call.z.value, float) or isinstance(call.z.value, int):
                return call.z.value
            else:
                # put it at the back
                return -np.inf

        calls = self._calls
        zs = np.array([_z(c) for c in calls])
        sorted_inds = zs.argsort()
        # TODO: ugh, this is ugly.  Test to find the optimal way to sort
        # while still ending up with a list
        return _call.make_callgroup(np.array(calls)[sorted_inds].tolist())