# Buggy code
def ensure_parameters_in_bounds(self):
    """For all active components, snaps their free parameter values to
    be within their boundaries (if bounded). Does not touch the array of
    values.
    """
    for component in self:
        if component.active:
            for param in component.free_parameters:
                bmin = -np.inf if param.bmin is None else param.bmin
                bmax = np.inf if param.bmax is None else param.bmax
                if not bmin <= param.value <= bmax:
                    min_d = np.abs(param.value - bmin)
                    max_d = np.abs(param.value - bmax)
                    if min_d < max_d:
                        param.value = bmin
                    else:
                        param.value = bmax


# Traceback (TypeError)
TypeError                                 Traceback (most recent call last)
<ipython-input-9-b81665222e1f> in <module>()
----> 1 m1.multifit(fitter='mpfit', bounded=True, kind='smart')

/home/magnunor/Documents/HyperSpy_project/HyperSpy/hyperspy/model.py in multifit(self, mask, fetch_only_fixed, autosave, autosave_every, show_progressbar, **kwargs)
   1446             if mask is None or not mask[index[::-1]]:
   1447                 self.fetch_stored_values(only_fixed=fetch_only_fixed)
-> 1448                 self.fit(**kwargs)
   1449                 i += 1
   1450                 if maxval > 0:

/home/magnunor/Documents/HyperSpy_project/HyperSpy/hyperspy/models/eelsmodel.py in fit(self, fitter, method, grad, bounded, ext_bounding, update_plot, kind, **kwargs)
    344                            ext_bounding=ext_bounding,
    345                            update_plot=update_plot,
--> 346                            **kwargs)
    347         elif kind == 'std':
    348             Model.fit(self,

/home/magnunor/Documents/HyperSpy_project/HyperSpy/hyperspy/models/eelsmodel.py in smart_fit(self, start_energy, **kwargs)
    383         # Fit the edges
    384         for i in range(0, len(self._active_edges)):
--> 385             self._fit_edge(i, start_energy, **kwargs)
    386 
    387     def _get_first_ionization_edge_energy(self, start_energy=None):

/home/magnunor/Documents/HyperSpy_project/HyperSpy/hyperspy/models/eelsmodel.py in _fit_edge(self, edgenumber, start_energy, **kwargs)
    558             self.set_signal_range(start_energy, nextedgeenergy)
    559             self.enable_fine_structure(to_activate_fs)
--> 560             self.fit(**kwargs)
    561 
    562         self.enable_edges(edges_to_activate)

/home/magnunor/Documents/HyperSpy_project/HyperSpy/hyperspy/models/eelsmodel.py in fit(self, fitter, method, grad, bounded, ext_bounding, update_plot, kind, **kwargs)
    353                       ext_bounding=ext_bounding,
    354                       update_plot=update_plot,
--> 355                       **kwargs)
    356         else:
    357             raise ValueError('kind must be either \'std\' or \'smart\'.'

/home/magnunor/Documents/HyperSpy_project/HyperSpy/hyperspy/model.py in fit(self, fitter, method, grad, bounded, ext_bounding, update_plot, **kwargs)
   1185                 # this has to be done before setting the p0, so moved things
   1186                 # around
-> 1187                 self.ensure_parameters_in_bounds()
   1188 
   1189         self.p_std = None

/home/magnunor/Documents/HyperSpy_project/HyperSpy/hyperspy/model.py in ensure_parameters_in_bounds(self)
    602                     bmin = -np.inf if param.bmin is None else param.bmin
    603                     bmax = np.inf if param.bmax is None else param.bmax
--> 604                     if not bmin <= param.value <= bmax:
    605                         min_d = np.abs(param.value - bmin)
    606                         max_d = np.abs(param.value - bmax)

TypeError: unorderable types: float() <= tuple()

# Fixed code
def ensure_parameters_in_bounds(self):
    """For all active components, snaps their free parameter values to
    be within their boundaries (if bounded). Does not touch the array of
    values.
    """
    for component in self:
        if component.active:
            for param in component.free_parameters:
                bmin = -np.inf if param.bmin is None else param.bmin
                bmax = np.inf if param.bmax is None else param.bmax
                if param._number_of_elements == 1:
                    if not bmin <= param.value <= bmax:
                        min_d = np.abs(param.value - bmin)
                        max_d = np.abs(param.value - bmax)
                        if min_d < max_d:
                            param.value = bmin
                        else:
                            param.value = bmax
                else:
                    values = np.array(param.value)
                    if param.bmin is not None:
                        minmask = values < bmin
                        values[minmask] = bmin
                    if param.bmax is not None:
                        maxmask = values > bmax
                        values[maxmask] = bmax
                    param.value = tuple(values)