def squish(x, range=(<NUM_LIT:0>, <NUM_LIT:1>), only_finite=True):
xtype = type(x)<EOL>if not hasattr(x, '<STR_LIT>'):<EOL><INDENT>x = np.asarray(x)<EOL><DEDENT>finite = np.isfinite(x) if only_finite else True<EOL>x[np.logical_and(x < range[<NUM_LIT:0>], finite)] = range[<NUM_LIT:0>]<EOL>x[np.logical_and(x > range[<NUM_LIT:1>], finite)] = range[<NUM_LIT:1>]<EOL>if not isinstance(x, xtype):<EOL><INDENT>x = xtype(x)<EOL><DEDENT>return x<EOL>
Squish values into range.

Parameters
----------
x : array_like
    Values that should have out of range values squished.
range : tuple
    The range onto which to squish the values.
only_finite: boolean
    When true, only squishes finite values.

Returns
-------
out : array_like
    Values with out of range values squished.

Examples
--------
>>> squish([-1.5, 0.2, 0.5, 0.8, 1.0, 1.2])
[0.0, 0.2, 0.5, 0.8, 1.0, 1.0]

>>> squish([-np.inf, -1.5, 0.2, 0.5, 0.8, 1.0, np.inf], only_finite=False)
[0.0, 0.0, 0.2, 0.5, 0.8, 1.0, 1.0]