<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def read_data_ext(self, model: str, field: str, idx=None, astype=None):
 """ Return a field of a model or group at the given indices :param str model: name of the group or model to retrieve :param str field: name of the field :param list, int, float str idx: idx of elements to access :param type astype: type cast :return: """

        ret = list()

        if model in self.system.devman.devices:
            ret = self.system.__dict__[model].get_field(field, idx)

        elif model in self.system.devman.group.keys():
            # ===============================================================
            # Since ``self.system.devman.group`` is an unordered dictionary,
            #   ``idx`` must be given to retrieve ``field`` across models.
            #
            # Returns a matrix by default
            # ===============================================================
            assert idx is not None, \
                'idx must be specified when accessing group fields'
            astype = matrix

            for item in idx:
                dev_name = self.system.devman.group[model].get(item, None)
                ret.append(self.read_data_ext(dev_name, field, idx=item))

        else:
            raise NameError(
                'Model or Group <{0}> does not exist.'.format(model))

        if (ret is None) or isinstance(ret, (int, float, str)):
            return ret
        elif astype is None:
            return ret
        else:
            return astype(ret)