Removes the nan, negative, and inf values in two numpy arrays
518135
def treat_values(simulated_array, observed_array, replace_nan=None, replace_inf=None,
                 remove_neg=False, remove_zero=False):
    """"""
    sim_copy = np.copy(simulated_array)
    obs_copy = np.copy(observed_array)

    # Checking to see if the vectors are the same length
    assert sim_copy.ndim == 1, "The simulated array is not one dimensional."
    assert obs_copy.ndim == 1, "The observed array is not one dimensional."

    if sim_copy.size != obs_copy.size:
        raise RuntimeError("The two ndarrays are not the same size.")

    # Treat missing data in observed_array and simulated_array, rows in simulated_array or
    # observed_array that contain nan values
    all_treatment_array = np.ones(obs_copy.size, dtype=bool)

    if np.any(np.isnan(obs_copy)) or np.any(np.isnan(sim_copy)):
        if replace_nan is not None:
            # Finding the NaNs
            sim_nan = np.isnan(sim_copy)
            obs_nan = np.isnan(obs_copy)
            # Replacing the NaNs with the input
            sim_copy[sim_nan] = replace_nan
            obs_copy[obs_nan] = replace_nan

            warnings.warn("Elements(s) {} contained NaN values in the simulated array and "
                          "elements(s) {} contained NaN values in the observed array and have been "
                          "replaced (Elements are zero indexed).".format(np.where(sim_nan)[0],
                                                                         np.where(obs_nan)[0]),
                          UserWarning)
        else:
            # Getting the indices of the nan values, combining them, and informing user.
            nan_indices_fcst = ~np.isnan(sim_copy)
            nan_indices_obs = ~np.isnan(obs_copy)
            all_nan_indices = np.logical_and(nan_indices_fcst, nan_indices_obs)
            all_treatment_array = np.logical_and(all_treatment_array, all_nan_indices)

            warnings.warn("Row(s) {} contained NaN values and the row(s) have been "
                          "removed (Rows are zero indexed).".format(np.where(~all_nan_indices)[0]),
                          UserWarning)

    if np.any(np.isinf(obs_copy)) or np.any(np.isinf(sim_copy)):
        if replace_nan is not None:
            # Finding the NaNs
            sim_inf = np.isinf(sim_copy)
            obs_inf = np.isinf(obs_copy)
            # Replacing the NaNs with the input
            sim_copy[sim_inf] = replace_inf
            obs_copy[obs_inf] = replace_inf

            warnings.warn("Elements(s) {} contained Inf values in the simulated array and "
                          "elements(s) {} contained Inf values in the observed array and have been "
                          "replaced (Elements are zero indexed).".format(np.where(sim_inf)[0],
                                                                         np.where(obs_inf)[0]),
                          UserWarning)
        else:
            inf_indices_fcst = ~(np.isinf(sim_copy))
            inf_indices_obs = ~np.isinf(obs_copy)
            all_inf_indices = np.logical_and(inf_indices_fcst, inf_indices_obs)
            all_treatment_array = np.logical_and(all_treatment_array, all_inf_indices)

            warnings.warn(
                "Row(s) {} contained Inf or -Inf values and the row(s) have been removed (Rows "
                "are zero indexed).".format(np.where(~all_inf_indices)[0]),
                UserWarning
            )

    # Treat zero data in observed_array and simulated_array, rows in simulated_array or
    # observed_array that contain zero values
    if remove_zero:
        if (obs_copy == 0).any() or (sim_copy == 0).any():
            zero_indices_fcst = ~(sim_copy == 0)
            zero_indices_obs = ~(obs_copy == 0)
            all_zero_indices = np.logical_and(zero_indices_fcst, zero_indices_obs)
            all_treatment_array = np.logical_and(all_treatment_array, all_zero_indices)

            warnings.warn(
                "Row(s) {} contained zero values and the row(s) have been removed (Rows are "
                "zero indexed).".format(np.where(~all_zero_indices)[0]),
                UserWarning
            )

    # Treat negative data in observed_array and simulated_array, rows in simulated_array or
    # observed_array that contain negative values

    # Ignore runtime warnings from comparing
    if remove_neg:
        with np.errstate(invalid='ignore'):
            obs_copy_bool = obs_copy < 0
            sim_copy_bool = sim_copy < 0

        if obs_copy_bool.any() or sim_copy_bool.any():
            neg_indices_fcst = ~sim_copy_bool
            neg_indices_obs = ~obs_copy_bool
            all_neg_indices = np.logical_and(neg_indices_fcst, neg_indices_obs)
            all_treatment_array = np.logical_and(all_treatment_array, all_neg_indices)

            warnings.warn("Row(s) {} contained negative values and the row(s) have been "
                          "removed (Rows are zero indexed).".format(np.where(~all_neg_indices)[0]),
                          UserWarning)

    obs_copy = obs_copy[all_treatment_array]
    sim_copy = sim_copy[all_treatment_array]

    return sim_copy, obs_copy
943203
def nan_maximum_filter(arr, ksize):
    '''
    
    '''
    out = np.empty_like(arr)
    _calc(arr, out, ksize//2)
    return out
410923
function removeFromArray(array, value, opt_notype) {
    var shift = 0;
    for (var i = 0; i < array.length; ++i) {
        if (array[i] === value || (opt_notype && array[i] === value)) {
            array.splice(i--, 1);
            shift++;
        }
    }
    return shift;
}
637882
def _reduce_mean_ignore_inf(x, axis):
    """"""
    mask = tf.not_equal(x, tf.float32.min)
    x_zeroed = tf.where(mask, x, tf.zeros_like(x))
    return (tf.reduce_sum(x_zeroed, axis) / tf.reduce_sum(
        tf.cast(mask, tf.float32), axis))
883868
def clean_coordinates(coords, silent=False):
    
    l1 = len(coords)
    coords = coords[~N.isnan(coords).any(axis=1)] # remove NaN values
    l2 = len(coords)
    if not silent:
        msg = "{0} coordinates".format(l2)
        if l2 < l1:
            msg += " ({0} removed as invalid)".format(l1-l2)
        print(msg)
    return coords
375919
def inpaint(self):
        

        import inpaint
        filled = inpaint.replace_nans(np.ma.filled(self.raster_data, np.NAN).astype(np.float32), 3, 0.01, 2)
        self.raster_data = np.ma.masked_invalid(filled)
70305
def remove_noise(time, magnitude, error, error_limit=3, std_limit=5):
    
    data, mjd = magnitude, time

    data_len = len(mjd)
    error_mean = np.mean(error)
    error_tolerance = error_limit * (error_mean or 1)
    data_mean = np.mean(data)
    data_std = np.std(data)

    mjd_out, data_out, error_out = [], [], []
    for i in range(data_len):
        is_not_noise = (
            error[i] < error_tolerance and
            (np.absolute(data[i] - data_mean) / data_std) < std_limit)

        if is_not_noise:
            mjd_out.append(mjd[i])
            data_out.append(data[i])
            error_out.append(error[i])

    data_out = np.asarray(data_out)
    mjd_out = np.asarray(mjd_out)
    error_out = np.asarray(error_out)

    return mjd_out, data_out, error_out
741075
def _remove_na_single(x, axis='rows'):
    
    if x.ndim == 1:
        # 1D arrays
        x_mask = ~np.isnan(x)
    else:
        # 2D arrays
        ax = 1 if axis == 'rows' else 0
        x_mask = ~np.any(np.isnan(x), axis=ax)
    # Check if missing values are present
    if ~x_mask.all():
        ax = 0 if axis == 'rows' else 1
        ax = 0 if x.ndim == 1 else ax
        x = x.compress(x_mask, axis=ax)
    return x
987976
def truncate_array(array1, array2, position):
    """"""

    slices = []
    for i in range(array1.ndim):
        xmin = 0
        xmax = array1.shape[i]
        dxlo = array1.shape[i] // 2
        dxhi = array1.shape[i] - dxlo
        if position[i] - dxlo < 0:
            xmin = max(dxlo - position[i], 0)

        if position[i] + dxhi > array2.shape[i]:
            xmax = array1.shape[i] - (position[i] + dxhi - array2.shape[i])
            xmax = max(xmax, 0)
        slices += [slice(xmin, xmax)]

    return array1[slices]
447159
def mask_negative(self):
        """"""
        self.mask = np.logical_and(self.mask, ~(self.intensity < 0))
603316
def __convert_none_to_zero(self, ts):
        

        if not ts:
            return ts

        ts_clean = [val if val else 0 for val in ts]

        return ts_clean
534589
function min (arr) {
    if (isArray(arr) && !(arr[0] instanceof Array)) {
        // Filter out undefined, null and NaN values
        const filteredValues = getFilteredValues(arr);

        return (filteredValues.length) ? Math.min(...filteredValues) : InvalidAwareTypes.NULL;
    }
    return InvalidAwareTypes.NULL;
}
1209652
def remove_na_arraylike(arr):
    
    if is_extension_array_dtype(arr):
        return arr[notna(arr)]
    else:
        return arr[notna(lib.values_from_object(arr))]
919649
def remove_length_outliers(df, columnname):
    """"""
    return df[df[columnname] < (np.median(df[columnname]) + 3 * np.std(df[columnname]))]
776212
def clean(self,x):
        """"""
        return x[~np.any(np.isnan(x) | np.isinf(x),axis=1)]
764305
function compareArrays(array1, array2, dontConvert) {
        var len = Math.min(array1.length, array2.length),
            lengthDiff = Math.abs(array1.length - array2.length),
            diffs = 0,
            i;
        for (i = 0; i < len; i++) {
            if ((dontConvert && array1[i] !== array2[i]) ||
                (!dontConvert && toInt(array1[i]) !== toInt(array2[i]))) {
                diffs++;
            }
        }
        return diffs + lengthDiff;
    }
237445
def merge_values(values1,values2):
    '''
    
    '''
    array1 = values_to_array(values1)
    array2 = values_to_array(values2)

    if array1.size == 0:
        return array2
    if array2.size == 0:
        return array1

    merged_array = []
    for row_array1 in array1:
        for row_array2 in array2:
            merged_row = np.hstack((row_array1,row_array2))
            merged_array.append(merged_row)
    return np.atleast_2d(merged_array)