Python numpy.alltrue() Examples

The following are 30 code examples for showing how to use numpy.alltrue(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module numpy , or try the search function .

Example 1
Project: NeuroKit   Author: neuropsychology   File: tests_emg.py    License: MIT License 6 votes vote down vote up
def test_emg_eventrelated():

    emg = nk.emg_simulate(duration=20, sampling_rate=1000, burst_number=3)
    emg_signals, info = nk.emg_process(emg, sampling_rate=1000)
    epochs = nk.epochs_create(
        emg_signals, events=[3000, 6000, 9000], sampling_rate=1000, epochs_start=-0.1, epochs_end=1.9
    )
    emg_eventrelated = nk.emg_eventrelated(epochs)

    # Test amplitude features
    no_activation = np.where(emg_eventrelated["EMG_Activation"] == 0)[0][0]
    assert int(pd.DataFrame(emg_eventrelated.values[no_activation]).isna().sum()) == 4

    assert np.alltrue(
        np.nansum(np.array(emg_eventrelated["EMG_Amplitude_Mean"]))
        < np.nansum(np.array(emg_eventrelated["EMG_Amplitude_Max"]))
    )

    assert len(emg_eventrelated["Label"]) == 3 
Example 2
Project: NeuroKit   Author: neuropsychology   File: tests_rsp.py    License: MIT License 6 votes vote down vote up
def test_rsp_eventrelated():

    rsp, info = nk.rsp_process(nk.rsp_simulate(duration=30, random_state=42))
    epochs = nk.epochs_create(rsp, events=[5000, 10000, 15000], epochs_start=-0.1, epochs_end=1.9)
    rsp_eventrelated = nk.rsp_eventrelated(epochs)

    # Test rate features
    assert np.alltrue(np.array(rsp_eventrelated["RSP_Rate_Min"]) < np.array(rsp_eventrelated["RSP_Rate_Mean"]))

    assert np.alltrue(np.array(rsp_eventrelated["RSP_Rate_Mean"]) < np.array(rsp_eventrelated["RSP_Rate_Max"]))

    # Test amplitude features
    assert np.alltrue(
        np.array(rsp_eventrelated["RSP_Amplitude_Min"]) < np.array(rsp_eventrelated["RSP_Amplitude_Mean"])
    )

    assert np.alltrue(
        np.array(rsp_eventrelated["RSP_Amplitude_Mean"]) < np.array(rsp_eventrelated["RSP_Amplitude_Max"])
    )

    assert len(rsp_eventrelated["Label"]) == 3 
Example 3
Project: scikit-multiflow   Author: scikit-multiflow   File: test_leverage_bagging.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def run_prequential_supervised(stream, learner, max_samples, n_wait, y_expected=None):
    stream.restart()

    y_pred = np.zeros(max_samples // n_wait, dtype=np.int)
    y_true = np.zeros(max_samples // n_wait, dtype=np.int)
    j = 0

    for i in range(max_samples):
        X, y = stream.next_sample()
        # Test every n samples
        if i % n_wait == 0:
            y_pred[j] = int(learner.predict(X)[0])
            y_true[j] = (y[0])
            j += 1
        learner.partial_fit(X, y, classes=stream.target_values)

    assert type(learner.predict(X)) == np.ndarray

    if y_expected is not None:
        assert np.alltrue(y_pred == y_expected) 
Example 4
Project: scikit-multiflow   Author: scikit-multiflow   File: test_missing_values_cleaner.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_missing_values_cleaner(test_path):

    test_file = os.path.join(test_path, 'data_nan.npy')
    X_nan = np.load(test_file)
    X = copy(X_nan)

    cleaner = MissingValuesCleaner(missing_value=np.nan, strategy='zero')

    X_complete = cleaner.transform(X)

    test_file = os.path.join(test_path, 'data_complete.npy')
    X_expected = np.load(test_file)
    assert np.alltrue(X_complete == X_expected)

    expected_info = "MissingValuesCleaner(missing_value=[nan], new_value=1, strategy='zero',\n" \
                    "                     window_size=200)"
    assert cleaner.get_info() == expected_info

    assert cleaner._estimator_type == 'transform' 
Example 5
def test_windowed_standard_scaler(test_path):
    X_orig = np.array([[1., 2., 3., 4.], [2., 3., 4., 5.], [3., 4., 5., 6.], [5., 4., 3., 2.], [4., 3., 2., 1.], [0., 1., 0., 1.], [3., 2., 3., 4.],
                       [1., 2., 3., 4.], [2., 3., 4., 5.], [3., 4., 5., 6.], [5., 4., 3., 2.], [4., 3., 2., 1.], [0., 1., 0., 1.], [3., 2., 3., 4.],
                       [1., 2., 3., 4.], [2., 3., 4., 5.], [3., 4., 5., 6.], [5., 4., 3., 2.], [4., 3., 2., 1.], [0., 1., 0., 1.], [3., 2., 3., 4.],
                       [1., 2., 3., 4.], [2., 3., 4., 5.], [3., 4., 5., 6.], [5., 4., 3., 2.], [4., 3., 2., 1.], [0., 1., 0., 1.], [3., 2., 3., 4.],
                       [1., 2., 3., 4.], [2., 3., 4., 5.], [3., 4., 5., 6.], [5., 4., 3., 2.], [4., 3., 2., 1.], [0., 1., 0., 1.], [3., 2., 3., 4.],
                       [1., 2., 3., 4.], [2., 3., 4., 5.], [3., 4., 5., 6.], [5., 4., 3., 2.], [4., 3., 2., 1.], [0., 1., 0., 1.], [3., 2., 3., 4.],
                       [1., 2., 3., 4.], [2., 3., 4., 5.], [3., 4., 5., 6.], [5., 4., 3., 2.], [4., 3., 2., 1.], [0., 1., 0., 1.], [3., 2., 3., 4.],
                       [1., 2., 3., 4.], [2., 3., 4., 5.], [3., 4., 5., 6.], [5., 4., 3., 2.], [4., 3., 2., 1.], [0., 1., 0., 1.], [3., 2., 3., 4.],
                       [1., 2., 3., 4.], [2., 3., 4., 5.], [3., 4., 5., 6.], [5., 4., 3., 2.], [4., 3., 2., 1.], [0., 1., 0., 1.], [3., 2., 3., 4.],
                       [1., 2., 3., 4.], [2., 3., 4., 5.], [3., 4., 5., 6.], [5., 4., 3., 2.], [4., 3., 2., 1.], [0., 1., 0., 1.], [3., 2., 3., 4.],
                       [1., 2., 3., 4.], [2., 3., 4., 5.], [3., 4., 5., 6.], [5., 4., 3., 2.], [4., 3., 2., 1.], [0., 1., 0., 1.], [3., 2., 3., 4.]])
    X = copy(X_orig)

    cleaner = WindowedStandardScaler(window_size=20)

    X_complete = cleaner.transform(X)

    test_file = os.path.join(test_path, 'std_scaler.npy')
    X_expected = np.load(test_file)

    assert np.alltrue(X_complete == X_expected) 
Example 6
Project: scikit-multiflow   Author: scikit-multiflow   File: test_windowed_minmax_scaler.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_windowed_minmax_scaler(test_path):
    X_orig = np.array([[1., 2., 3., 4.], [2., 3., 4., 5.], [3., 4., 5., 6.], [5., 4., 3., 2.], [4., 3., 2., 1.], [0., 1., 0., 1.], [3., 2., 3., 4.],
                       [1., 2., 3., 4.], [2., 3., 4., 5.], [3., 4., 5., 6.], [5., 4., 3., 2.], [4., 3., 2., 1.], [0., 1., 0., 1.], [3., 2., 3., 4.],
                       [1., 2., 3., 4.], [2., 3., 4., 5.], [3., 4., 5., 6.], [5., 4., 3., 2.], [4., 3., 2., 1.], [0., 1., 0., 1.], [3., 2., 3., 4.],
                       [1., 2., 3., 4.], [2., 3., 4., 5.], [3., 4., 5., 6.], [5., 4., 3., 2.], [4., 3., 2., 1.], [0., 1., 0., 1.], [3., 2., 3., 4.],
                       [1., 2., 3., 4.], [2., 3., 4., 5.], [3., 4., 5., 6.], [5., 4., 3., 2.], [4., 3., 2., 1.], [0., 1., 0., 1.], [3., 2., 3., 4.],
                       [1., 2., 3., 4.], [2., 3., 4., 5.], [3., 4., 5., 6.], [5., 4., 3., 2.], [4., 3., 2., 1.], [0., 1., 0., 1.], [3., 2., 3., 4.],
                       [1., 2., 3., 4.], [2., 3., 4., 5.], [3., 4., 5., 6.], [5., 4., 3., 2.], [4., 3., 2., 1.], [0., 1., 0., 1.], [3., 2., 3., 4.],
                       [1., 2., 3., 4.], [2., 3., 4., 5.], [3., 4., 5., 6.], [5., 4., 3., 2.], [4., 3., 2., 1.], [0., 1., 0., 1.], [3., 2., 3., 4.],
                       [1., 2., 3., 4.], [2., 3., 4., 5.], [3., 4., 5., 6.], [5., 4., 3., 2.], [4., 3., 2., 1.], [0., 1., 0., 1.], [3., 2., 3., 4.],
                       [1., 2., 3., 4.], [2., 3., 4., 5.], [3., 4., 5., 6.], [5., 4., 3., 2.], [4., 3., 2., 1.], [0., 1., 0., 1.], [3., 2., 3., 4.],
                       [1., 2., 3., 4.], [2., 3., 4., 5.], [3., 4., 5., 6.], [5., 4., 3., 2.], [4., 3., 2., 1.], [0., 1., 0., 1.], [3., 2., 3., 4.]])
    X = copy(X_orig)

    cleaner = WindowedMinmaxScaler(window_size=20)

    X_complete = cleaner.transform(X)

    test_file = os.path.join(test_path, 'minmax_scaler.npy')
    X_expected = np.load(test_file)

    assert np.alltrue(X_complete == X_expected) 
Example 7
Project: scikit-multiflow   Author: scikit-multiflow   File: test_measure_collection.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_regression_measurements():
    y_true = np.sin(range(100))
    y_pred = np.sin(range(100)) + .05

    measurements = RegressionMeasurements()
    for i in range(len(y_true)):
        measurements.add_result(y_true[i], y_pred[i])

    expected_mse = 0.0025000000000000022
    assert np.isclose(expected_mse, measurements.get_mean_square_error())

    expected_ae = 0.049999999999999906
    assert np.isclose(expected_ae, measurements.get_average_error())

    expected_info = 'RegressionMeasurements: - sample_count: 100 - mean_square_error: 0.002500 ' \
                    '- mean_absolute_error: 0.050000'
    assert expected_info == measurements.get_info()

    expected_last = (-0.9992068341863537, -0.9492068341863537)
    assert np.alltrue(expected_last == measurements.get_last())

    measurements.reset()
    assert measurements.sample_count == 0 
Example 8
Project: scikit-multiflow   Author: scikit-multiflow   File: test_agrawal_generator.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_agrawal_drift(test_path):
    stream = AGRAWALGenerator(random_state=1)
    X, y = stream.next_sample(10)
    stream.generate_drift()
    X_drift, y_drift = stream.next_sample(10)

    # Load test data corresponding to first 10 instances
    test_file = os.path.join(test_path, 'agrawal_stream_drift.npz')
    data = np.load(test_file)
    X_expected = data['X']
    y_expected = data['y']

    X = np.concatenate((X, X_drift))
    y = np.concatenate((y, y_drift))
    assert np.alltrue(X == X_expected)
    assert np.alltrue(y == y_expected) 
Example 9
Project: NeuroKit   Author: neuropsychology   File: tests_ecg.py    License: MIT License 5 votes vote down vote up
def test_ecg_eventrelated():

    ecg, info = nk.ecg_process(nk.ecg_simulate(duration=20))
    epochs = nk.epochs_create(ecg, events=[5000, 10000, 15000], epochs_start=-0.1, epochs_end=1.9)
    ecg_eventrelated = nk.ecg_eventrelated(epochs)

    # Test rate features
    assert np.alltrue(np.array(ecg_eventrelated["ECG_Rate_Min"]) < np.array(ecg_eventrelated["ECG_Rate_Mean"]))

    assert np.alltrue(np.array(ecg_eventrelated["ECG_Rate_Mean"]) < np.array(ecg_eventrelated["ECG_Rate_Max"]))

    assert len(ecg_eventrelated["Label"]) == 3 
Example 10
Project: seizure-prediction   Author: MichaelHills   File: mat_to_hdf5.py    License: MIT License 5 votes vote down vote up
def add_channels(self, channels):
        if self.channels is None:
            self.channels = channels
        else:
            assert np.alltrue(channels == self.channels) 
Example 11
Project: recruit   Author: Frank-qlu   File: test_function_base.py    License: Apache License 2.0 5 votes vote down vote up
def test_nd(self):
        y1 = [[0, 0, 1], [0, 1, 1], [1, 1, 1]]
        assert_(not np.all(y1))
        assert_array_equal(np.alltrue(y1, axis=0), [0, 0, 1])
        assert_array_equal(np.alltrue(y1, axis=1), [0, 0, 1]) 
Example 12
Project: recruit   Author: Frank-qlu   File: testutils.py    License: Apache License 2.0 5 votes vote down vote up
def fail_if_array_equal(x, y, err_msg='', verbose=True):
    """
    Raises an assertion error if two masked arrays are not equal elementwise.

    """
    def compare(x, y):
        return (not np.alltrue(approx(x, y)))
    assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose,
                         header='Arrays are not equal') 
Example 13
Project: recruit   Author: Frank-qlu   File: test_numeric.py    License: Apache License 2.0 5 votes vote down vote up
def test_values(self):
        expected = np.array(list(self.makegen()))
        a = np.fromiter(self.makegen(), int)
        a20 = np.fromiter(self.makegen(), int, 20)
        assert_(np.alltrue(a == expected, axis=0))
        assert_(np.alltrue(a20 == expected[:20], axis=0)) 
Example 14
Project: recruit   Author: Frank-qlu   File: test_regression.py    License: Apache License 2.0 5 votes vote down vote up
def test_method_args(self):
        # Make sure methods and functions have same default axis
        # keyword and arguments
        funcs1 = ['argmax', 'argmin', 'sum', ('product', 'prod'),
                 ('sometrue', 'any'),
                 ('alltrue', 'all'), 'cumsum', ('cumproduct', 'cumprod'),
                 'ptp', 'cumprod', 'prod', 'std', 'var', 'mean',
                 'round', 'min', 'max', 'argsort', 'sort']
        funcs2 = ['compress', 'take', 'repeat']

        for func in funcs1:
            arr = np.random.rand(8, 7)
            arr2 = arr.copy()
            if isinstance(func, tuple):
                func_meth = func[1]
                func = func[0]
            else:
                func_meth = func
            res1 = getattr(arr, func_meth)()
            res2 = getattr(np, func)(arr2)
            if res1 is None:
                res1 = arr

            if res1.dtype.kind in 'uib':
                assert_((res1 == res2).all(), func)
            else:
                assert_(abs(res1-res2).max() < 1e-8, func)

        for func in funcs2:
            arr1 = np.random.rand(8, 7)
            arr2 = np.random.rand(8, 7)
            res1 = None
            if func == 'compress':
                arr1 = arr1.ravel()
                res1 = getattr(arr2, func)(arr1)
            else:
                arr2 = (15*arr2).astype(int).ravel()
            if res1 is None:
                res1 = getattr(arr1, func)(arr2)
            res2 = getattr(np, func)(arr1, arr2)
            assert_(abs(res1-res2).max() < 1e-8, func) 
Example 15
Project: recruit   Author: Frank-qlu   File: test_regression.py    License: Apache License 2.0 5 votes vote down vote up
def test_fromiter_bytes(self):
        # Ticket #1058
        a = np.fromiter(list(range(10)), dtype='b')
        b = np.fromiter(list(range(10)), dtype='B')
        assert_(np.alltrue(a == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
        assert_(np.alltrue(b == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]))) 
Example 16
Project: KAIR   Author: cszn   File: utils_deblur.py    License: MIT License 5 votes vote down vote up
def zero_pad(image, shape, position='corner'):
    """
    Extends image to a certain size with zeros
    Parameters
    ----------
    image: real 2d `numpy.ndarray`
        Input image
    shape: tuple of int
        Desired output shape of the image
    position : str, optional
        The position of the input image in the output one:
            * 'corner'
                top-left corner (default)
            * 'center'
                centered
    Returns
    -------
    padded_img: real `numpy.ndarray`
        The zero-padded image
    """
    shape = np.asarray(shape, dtype=int)
    imshape = np.asarray(image.shape, dtype=int)
    if np.alltrue(imshape == shape):
        return image
    if np.any(shape <= 0):
        raise ValueError("ZERO_PAD: null or negative shape given")
    dshape = shape - imshape
    if np.any(dshape < 0):
        raise ValueError("ZERO_PAD: target size smaller than source one")
    pad_img = np.zeros(shape, dtype=image.dtype)
    idx, idy = np.indices(imshape)
    if position == 'center':
        if np.any(dshape % 2 != 0):
            raise ValueError("ZERO_PAD: source and target shapes "
                             "have different parity.")
        offx, offy = dshape // 2
    else:
        offx, offy = (0, 0)
    pad_img[idx + offx, idy + offy] = image
    return pad_img 
Example 17
Project: KAIR   Author: cszn   File: utils_sisr.py    License: MIT License 5 votes vote down vote up
def zero_pad(image, shape, position='corner'):
    """
    Extends image to a certain size with zeros
    Parameters
    ----------
    image: real 2d `numpy.ndarray`
        Input image
    shape: tuple of int
        Desired output shape of the image
    position : str, optional
        The position of the input image in the output one:
            * 'corner'
                top-left corner (default)
            * 'center'
                centered
    Returns
    -------
    padded_img: real `numpy.ndarray`
        The zero-padded image
    """
    shape = np.asarray(shape, dtype=int)
    imshape = np.asarray(image.shape, dtype=int)
    if np.alltrue(imshape == shape):
        return image
    if np.any(shape <= 0):
        raise ValueError("ZERO_PAD: null or negative shape given")
    dshape = shape - imshape
    if np.any(dshape < 0):
        raise ValueError("ZERO_PAD: target size smaller than source one")
    pad_img = np.zeros(shape, dtype=image.dtype)
    idx, idy = np.indices(imshape)
    if position == 'center':
        if np.any(dshape % 2 != 0):
            raise ValueError("ZERO_PAD: source and target shapes "
                             "have different parity.")
        offx, offy = dshape // 2
    else:
        offx, offy = (0, 0)
    pad_img[idx + offx, idy + offy] = image
    return pad_img 
Example 18
Project: lambda-packs   Author: ryfeus   File: testutils.py    License: MIT License 5 votes vote down vote up
def fail_if_array_equal(x, y, err_msg='', verbose=True):
    """
    Raises an assertion error if two masked arrays are not equal elementwise.

    """
    def compare(x, y):
        return (not np.alltrue(approx(x, y)))
    assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose,
                         header='Arrays are not equal') 
Example 19
Project: lambda-packs   Author: ryfeus   File: fitpack2.py    License: MIT License 5 votes vote down vote up
def __init__(self, x, y, t, w=None, bbox=[None]*2, k=3,
                 ext=0, check_finite=False):

        if check_finite:
            w_finite = np.isfinite(w).all() if w is not None else True
            if (not np.isfinite(x).all() or not np.isfinite(y).all() or
                    not w_finite or not np.isfinite(t).all()):
                raise ValueError("Input(s) must not contain NaNs or infs.")
        if not all(diff(x) > 0.0):
            raise ValueError('x must be strictly increasing')

        # _data == x,y,w,xb,xe,k,s,n,t,c,fp,fpint,nrdata,ier
        xb = bbox[0]
        xe = bbox[1]
        if xb is None:
            xb = x[0]
        if xe is None:
            xe = x[-1]
        t = concatenate(([xb]*(k+1), t, [xe]*(k+1)))
        n = len(t)
        if not alltrue(t[k+1:n-k]-t[k:n-k-1] > 0, axis=0):
            raise ValueError('Interior knots t must satisfy '
                             'Schoenberg-Whitney conditions')
        if not dfitpack.fpchec(x, t, k) == 0:
            raise ValueError(_fpchec_error_string)
        data = dfitpack.fpcurfm1(x, y, k, t, w=w, xb=xb, xe=xe)
        self._data = data[:-3] + (None, None, data[-1])
        self._reset_class()

        try:
            self.ext = _extrap_modes[ext]
        except KeyError:
            raise ValueError("Unknown extrapolation mode %s." % ext)


################ Bivariate spline #################### 
Example 20
Project: lambda-packs   Author: ryfeus   File: optimize.py    License: MIT License 5 votes vote down vote up
def derivative(self, x, *args):
        if self.jac is not None and numpy.alltrue(x == self.x):
            return self.jac
        else:
            self(x, *args)
            return self.jac 
Example 21
Project: lambda-packs   Author: ryfeus   File: test_function_base.py    License: MIT License 5 votes vote down vote up
def test_nd(self):
        y1 = [[0, 0, 1], [0, 1, 1], [1, 1, 1]]
        assert_(not np.all(y1))
        assert_array_equal(np.alltrue(y1, axis=0), [0, 0, 1])
        assert_array_equal(np.alltrue(y1, axis=1), [0, 0, 1]) 
Example 22
Project: lambda-packs   Author: ryfeus   File: testutils.py    License: MIT License 5 votes vote down vote up
def fail_if_array_equal(x, y, err_msg='', verbose=True):
    """
    Raises an assertion error if two masked arrays are not equal elementwise.

    """
    def compare(x, y):
        return (not np.alltrue(approx(x, y)))
    assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose,
                         header='Arrays are not equal') 
Example 23
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: test_function_base.py    License: MIT License 5 votes vote down vote up
def test_nd(self):
        y1 = [[0, 0, 1], [0, 1, 1], [1, 1, 1]]
        assert_(not np.all(y1))
        assert_array_equal(np.alltrue(y1, axis=0), [0, 0, 1])
        assert_array_equal(np.alltrue(y1, axis=1), [0, 0, 1]) 
Example 24
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: testutils.py    License: MIT License 5 votes vote down vote up
def fail_if_array_equal(x, y, err_msg='', verbose=True):
    """
    Raises an assertion error if two masked arrays are not equal elementwise.

    """
    def compare(x, y):
        return (not np.alltrue(approx(x, y)))
    assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose,
                         header='Arrays are not equal') 
Example 25
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: test_numeric.py    License: MIT License 5 votes vote down vote up
def test_values(self):
        expected = np.array(list(self.makegen()))
        a = np.fromiter(self.makegen(), int)
        a20 = np.fromiter(self.makegen(), int, 20)
        self.assertTrue(np.alltrue(a == expected, axis=0))
        self.assertTrue(np.alltrue(a20 == expected[:20], axis=0)) 
Example 26
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: test_regression.py    License: MIT License 5 votes vote down vote up
def test_method_args(self, level=rlevel):
        # Make sure methods and functions have same default axis
        # keyword and arguments
        funcs1 = ['argmax', 'argmin', 'sum', ('product', 'prod'),
                 ('sometrue', 'any'),
                 ('alltrue', 'all'), 'cumsum', ('cumproduct', 'cumprod'),
                 'ptp', 'cumprod', 'prod', 'std', 'var', 'mean',
                 'round', 'min', 'max', 'argsort', 'sort']
        funcs2 = ['compress', 'take', 'repeat']

        for func in funcs1:
            arr = np.random.rand(8, 7)
            arr2 = arr.copy()
            if isinstance(func, tuple):
                func_meth = func[1]
                func = func[0]
            else:
                func_meth = func
            res1 = getattr(arr, func_meth)()
            res2 = getattr(np, func)(arr2)
            if res1 is None:
                res1 = arr

            if res1.dtype.kind in 'uib':
                assert_((res1 == res2).all(), func)
            else:
                assert_(abs(res1-res2).max() < 1e-8, func)

        for func in funcs2:
            arr1 = np.random.rand(8, 7)
            arr2 = np.random.rand(8, 7)
            res1 = None
            if func == 'compress':
                arr1 = arr1.ravel()
                res1 = getattr(arr2, func)(arr1)
            else:
                arr2 = (15*arr2).astype(int).ravel()
            if res1 is None:
                res1 = getattr(arr1, func)(arr2)
            res2 = getattr(np, func)(arr1, arr2)
            assert_(abs(res1-res2).max() < 1e-8, func) 
Example 27
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: test_regression.py    License: MIT License 5 votes vote down vote up
def test_fromiter_bytes(self):
        # Ticket #1058
        a = np.fromiter(list(range(10)), dtype='b')
        b = np.fromiter(list(range(10)), dtype='B')
        assert_(np.alltrue(a == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
        assert_(np.alltrue(b == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]))) 
Example 28
Project: vnpy_crypto   Author: birforce   File: test_function_base.py    License: MIT License 5 votes vote down vote up
def test_nd(self):
        y1 = [[0, 0, 1], [0, 1, 1], [1, 1, 1]]
        assert_(not np.all(y1))
        assert_array_equal(np.alltrue(y1, axis=0), [0, 0, 1])
        assert_array_equal(np.alltrue(y1, axis=1), [0, 0, 1]) 
Example 29
Project: vnpy_crypto   Author: birforce   File: testutils.py    License: MIT License 5 votes vote down vote up
def fail_if_array_equal(x, y, err_msg='', verbose=True):
    """
    Raises an assertion error if two masked arrays are not equal elementwise.

    """
    def compare(x, y):
        return (not np.alltrue(approx(x, y)))
    assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose,
                         header='Arrays are not equal') 
Example 30
Project: vnpy_crypto   Author: birforce   File: test_numeric.py    License: MIT License 5 votes vote down vote up
def test_values(self):
        expected = np.array(list(self.makegen()))
        a = np.fromiter(self.makegen(), int)
        a20 = np.fromiter(self.makegen(), int, 20)
        assert_(np.alltrue(a == expected, axis=0))
        assert_(np.alltrue(a20 == expected[:20], axis=0))