当前位置: 首页>>代码示例>>Python>>正文


Python testing.assert_array_equal方法代码示例

本文整理汇总了Python中numpy.testing.assert_array_equal方法的典型用法代码示例。如果您正苦于以下问题:Python testing.assert_array_equal方法的具体用法?Python testing.assert_array_equal怎么用?Python testing.assert_array_equal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpy.testing的用法示例。


在下文中一共展示了testing.assert_array_equal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_linear_sum_assignment_input_validation

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_array_equal [as 别名]
def test_linear_sum_assignment_input_validation():
    assert_raises(ValueError, linear_sum_assignment, [1, 2, 3])

    C = [[1, 2, 3], [4, 5, 6]]
    assert_array_equal(linear_sum_assignment(C), linear_sum_assignment(np.asarray(C)))
    # assert_array_equal(linear_sum_assignment(C),
    #                    linear_sum_assignment(matrix(C)))

    I = np.identity(3)
    assert_array_equal(linear_sum_assignment(I.astype(np.bool)), linear_sum_assignment(I))
    assert_raises(ValueError, linear_sum_assignment, I.astype(str))

    I[0][0] = np.nan
    assert_raises(ValueError, linear_sum_assignment, I)

    I = np.identity(3)
    I[1][1] = np.inf
    assert_raises(ValueError, linear_sum_assignment, I) 
开发者ID:MolSSI,项目名称:QCElemental,代码行数:20,代码来源:test_scipy_hungarian.py

示例2: test_pickle

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_array_equal [as 别名]
def test_pickle():
    import pickle
    a = npc.Array.from_ndarray(arr, [lc, lc_add.conj()])
    b = random_Array((20, 15, 10), chinfo2, sort=False)
    a.test_sanity()
    b.test_sanity()
    aflat = a.to_ndarray()
    bflat = b.to_ndarray()
    data = {'a': a, 'b': b}
    stream = pickle.dumps(data)
    data2 = pickle.loads(stream)
    a2 = data2['a']
    b2 = data2['b']
    a.test_sanity()
    b.test_sanity()
    a2.test_sanity()
    b2.test_sanity()
    a2flat = a2.to_ndarray()
    b2flat = b2.to_ndarray()
    npt.assert_array_equal(aflat, a2flat)
    npt.assert_array_equal(bflat, b2flat) 
开发者ID:tenpy,项目名称:tenpy,代码行数:23,代码来源:test_np_conserved.py

示例3: test_logsol

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_array_equal [as 别名]
def test_logsol(self):
        # Test conversion tools related to log solar luminosity
        from astroNN.gaia import fakemag_to_logsol, absmag_to_logsol, logsol_to_absmag, logsol_to_fakemag
        self.assertEqual(logsol_to_fakemag(fakemag_to_logsol(100.)), 100.)
        npt.assert_array_equal(logsol_to_fakemag(fakemag_to_logsol([100., 100.])), [100., 100.])
        npt.assert_array_equal(logsol_to_fakemag(fakemag_to_logsol(np.array([100, 100, 100]))), [100., 100., 100.])
        self.assertEqual(fakemag_to_logsol(MAGIC_NUMBER), MAGIC_NUMBER)
        self.assertEqual(logsol_to_fakemag(fakemag_to_logsol(MAGIC_NUMBER)), MAGIC_NUMBER)
        self.assertEqual(np.any(fakemag_to_logsol([MAGIC_NUMBER, 1000]) == MAGIC_NUMBER), True)

        self.assertEqual(logsol_to_absmag(absmag_to_logsol(99.)), 99.)
        self.assertAlmostEqual(logsol_to_absmag(absmag_to_logsol(-99.)), -99.)
        npt.assert_array_equal(logsol_to_absmag(absmag_to_logsol([99., 99.])), [99., 99.])
        npt.assert_array_almost_equal(logsol_to_absmag(absmag_to_logsol([-99., -99.])), [-99., -99.])
        npt.assert_array_almost_equal(logsol_to_absmag(absmag_to_logsol(np.array([99., 99., 99.]))), [99., 99., 99.])
        self.assertEqual(absmag_to_logsol(MAGIC_NUMBER), MAGIC_NUMBER)
        self.assertEqual(logsol_to_absmag(absmag_to_logsol(MAGIC_NUMBER)), MAGIC_NUMBER)
        self.assertEqual(np.any(absmag_to_logsol([MAGIC_NUMBER, 1000]) == MAGIC_NUMBER), True) 
开发者ID:henrysky,项目名称:astroNN,代码行数:20,代码来源:test_gaia_tools.py

示例4: test_nio_NCFile_variable_append

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_array_equal [as 别名]
def test_nio_NCFile_variable_append(self):
        iobackend.set_backend('Nio')
        ncf = iobackend.NCFile(self.ncfaname, mode='a')
        nt = self.ncdims['t']
        t = ncf.variables['t']
        t[nt:] = self.t2
        v = ncf.variables['v']
        v[nt:, :] = self.v2
        ncf.close()
        ncfr = Nio.open_file(self.ncfaname)
        actual = ncfr.variables['t'][:]
        expected = np.concatenate((self.t, self.t2))
        print_test_msg('NCVariable append', actual=actual, expected=expected)
        npt.assert_array_equal(actual, expected, 'NCFile t-variable incorrect')
        actual = ncfr.variables['v'][:]
        expected = np.concatenate((self.v, self.v2))
        print_test_msg('NCVariable append', actual=actual, expected=expected)
        npt.assert_array_equal(
            actual, expected, 'NCFile 2d-variable incorrect')
        ncfr.close() 
开发者ID:NCAR,项目名称:PyReshaper,代码行数:22,代码来源:iobackendTests.py

示例5: test_nc4_NCFile_variable_append

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_array_equal [as 别名]
def test_nc4_NCFile_variable_append(self):
        iobackend.set_backend('netCDF4')
        ncf = iobackend.NCFile(self.ncfaname, mode='a')
        nt = self.ncdims['t']
        t = ncf.variables['t']
        t[nt:] = self.t2
        v = ncf.variables['v']
        v[nt:, :] = self.v2
        ncf.close()
        ncfr = Nio.open_file(self.ncfaname)
        actual = ncfr.variables['t'][:]
        expected = np.concatenate((self.t, self.t2))
        print_test_msg('NCVariable append', actual=actual, expected=expected)
        npt.assert_array_equal(actual, expected, 'NCFile t-variable incorrect')
        actual = ncfr.variables['v'][:]
        expected = np.concatenate((self.v, self.v2))
        print_test_msg('NCVariable append', actual=actual, expected=expected)
        npt.assert_array_equal(
            actual, expected, 'NCFile 2d-variable incorrect')
        ncfr.close() 
开发者ID:NCAR,项目名称:PyReshaper,代码行数:22,代码来源:iobackendTests.py

示例6: test_distance_mask_grid

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_array_equal [as 别名]
def test_distance_mask_grid():
    "Check that the mask works for grid input"
    region = (0, 5, -10, -4)
    shape = (7, 6)
    east, north = grid_coordinates(region, shape=shape)
    coords = {"easting": east[0, :], "northing": north[:, 0]}
    data_vars = {"scalars": (["northing", "easting"], np.ones(shape))}
    grid = xr.Dataset(data_vars, coords=coords)
    masked = distance_mask((2.5, -7.5), maxdist=2, grid=grid)
    true = [
        [np.nan, np.nan, np.nan, np.nan, np.nan, np.nan],
        [np.nan, np.nan, 1, 1, np.nan, np.nan],
        [np.nan, 1, 1, 1, 1, np.nan],
        [np.nan, 1, 1, 1, 1, np.nan],
        [np.nan, np.nan, 1, 1, np.nan, np.nan],
        [np.nan, np.nan, np.nan, np.nan, np.nan, np.nan],
        [np.nan, np.nan, np.nan, np.nan, np.nan, np.nan],
    ]
    npt.assert_array_equal(true, masked.scalars.values) 
开发者ID:fatiando,项目名称:verde,代码行数:21,代码来源:test_mask.py

示例7: check_pow

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_array_equal [as 别名]
def check_pow(self, lhs, arith1, rhs):
        ex = 'lhs {0} rhs'.format(arith1)
        expected = self.get_expected_pow_result(lhs, rhs)
        result = pd.eval(ex, engine=self.engine, parser=self.parser)

        if (np.isscalar(lhs) and np.isscalar(rhs) and
                _is_py3_complex_incompat(result, expected)):
            self.assertRaises(AssertionError, assert_array_equal, result,
                              expected)
        else:
            assert_allclose(result, expected)

            ex = '(lhs {0} rhs) {0} rhs'.format(arith1)
            result = pd.eval(ex, engine=self.engine, parser=self.parser)
            expected = self.get_expected_pow_result(
                self.get_expected_pow_result(lhs, rhs), rhs)
            assert_allclose(result, expected) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:19,代码来源:test_eval.py

示例8: test_split_streamline

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_array_equal [as 别名]
def test_split_streamline():
    streamlines = dts.Streamlines([np.array([[1.,2.,3.],
                                    [4.,5.,6.]]),
                                   np.array([[7.,8.,9.],
                                    [10.,11.,12.],
                                    [13., 14., 15.]])])
    assert streamlines == streamlines
    sl_to_split = 1
    split_idx = 1
    new_streamlines = aus.split_streamline(streamlines, sl_to_split, split_idx)
    test_streamlines = dts.Streamlines([np.array([[1., 2., 3.],
                                                  [4., 5., 6.]]),
                                        np.array([[7., 8., 9.]]),
                                        np.array([[10., 11., 12.],
                                                  [13., 14., 15.]])])

    # Test equality of the underlying dict items:
    for k in new_streamlines.__dict__.keys():
        if isinstance(new_streamlines.__dict__[k], np.ndarray):
            npt.assert_array_equal(
                new_streamlines.__dict__[k],
                test_streamlines.__dict__[k]
                )
        else:
            assert new_streamlines.__dict__[k] == test_streamlines.__dict__[k] 
开发者ID:yeatmanlab,项目名称:pyAFQ,代码行数:27,代码来源:test_streamlines.py

示例9: test_add_bundles

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_array_equal [as 别名]
def test_add_bundles():
    t1 = nib.streamlines.Tractogram(
            [np.array([[0, 0, 0], [0, 0, 0.5], [0, 0, 1], [0, 0, 1.5]]),
             np.array([[0, 0, 0], [0, 0.5, 0.5], [0, 1, 1]])])

    t2 = nib.streamlines.Tractogram(
        [np.array([[0, 0, 0], [0, 0, 0.5], [0, 0, 1], [0, 0, 1.5]]),
            np.array([[0, 0, 0], [0, 0.5, 0.5], [0, 1, 1]])])

    added = aus.add_bundles(t1, t2)
    test_tgram =nib.streamlines.Tractogram(
        [np.array([[0, 0, 0], [0, 0, 0.5], [0, 0, 1], [0, 0, 1.5]]),
            np.array([[0, 0, 0], [0, 0.5, 0.5], [0, 1, 1]]),
            np.array([[0, 0, 0], [0, 0, 0.5], [0, 0, 1], [0, 0, 1.5]]),
            np.array([[0, 0, 0], [0, 0.5, 0.5], [0, 1, 1]])])

    for sl1, sl2 in zip(added.streamlines, test_tgram.streamlines):
        npt.assert_array_equal(sl1, sl2) 
开发者ID:yeatmanlab,项目名称:pyAFQ,代码行数:20,代码来源:test_streamlines.py

示例10: test_gen_xrf_map_const_1

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_array_equal [as 别名]
def test_gen_xrf_map_const_1():
    r"""Successful generation of XRF map"""

    element_groups = {"Fe_K": {'area': 800}, "Se_L": {'area': 900}, "W_M": {'area': 1000}}
    background_area = 1000
    nx, ny = 50, 100

    total_area = sum([_["area"] for _ in element_groups.values()])
    total_area += background_area

    xrf_map, xx = gen_xrf_map_const(element_groups, nx=nx, ny=ny,
                                    incident_energy=12.0, background_area=background_area)
    assert xrf_map.shape == (ny, nx, 4096), "Incorrect shape of generated XRF maps"
    assert xx.shape == (4096,), "Incorrect shape of energy axis"
    npt.assert_array_equal(xrf_map[0, 0, :], xrf_map[1, 1, :],
                           err_msg="Elements of XRF map are not equal")
    npt.assert_almost_equal(np.sum(xrf_map[0, 0, :]), total_area,
                            err_msg="Area of the generated spectrum does not match the expected value")

    # Test generation of XRF map with different size spectrum
    xrf_map, xx = gen_xrf_map_const(element_groups, nx=nx, ny=ny, n_spectrum_points=1000,
                                    incident_energy=12.0, background_area=background_area)
    assert xrf_map.shape == (ny, nx, 1000), "Incorrect shape of generated XRF maps"
    assert xx.shape == (1000,), "Incorrect shape of energy axis" 
开发者ID:NSLS-II,项目名称:PyXRF,代码行数:26,代码来源:test_sim_xrf_scan_data.py

示例11: test_chunk_numpy_array

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_array_equal [as 别名]
def test_chunk_numpy_array(chunk_target, data_shape):
    """Basic functionailty tests for '_chunk_xrf_map_numpy"""

    data = np.random.random(data_shape)
    data_dask = _chunk_numpy_array(data, chunk_target)

    chunksize_expected = tuple([
        min(chunk_target[0], data_shape[0]),
        min(chunk_target[1], data_shape[1]),
        *data_shape[2:]])

    assert data_dask.shape == data.shape, "The shape of the original and chunked array don't match"
    assert data_dask.chunksize == chunksize_expected, \
        "The chunk size of the Dask array doesn't match the desired chunk size"
    npt.assert_array_equal(data_dask.compute(), data,
                           err_msg="The chunked array is different from the original array") 
开发者ID:NSLS-II,项目名称:PyXRF,代码行数:18,代码来源:test_map_processing.py

示例12: test_bbox_intersection

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_array_equal [as 别名]
def test_bbox_intersection():
    bbox_from_ext = mtrans.Bbox.from_extents
    inter = mtrans.Bbox.intersection

    from numpy.testing import assert_array_equal as assert_a_equal
    def assert_bbox_eq(bbox1, bbox2):
        assert_a_equal(bbox1.bounds, bbox2.bounds)

    r1 = bbox_from_ext(0, 0, 1, 1)
    r2 = bbox_from_ext(0.5, 0.5, 1.5, 1.5)
    r3 = bbox_from_ext(0.5, 0, 0.75, 0.75)
    r4 = bbox_from_ext(0.5, 1.5, 1, 2.5)
    r5 = bbox_from_ext(1, 1, 2, 2)

    # self intersection -> no change
    assert_bbox_eq(inter(r1, r1), r1)
    # simple intersection
    assert_bbox_eq(inter(r1, r2), bbox_from_ext(0.5, 0.5, 1, 1))
    # r3 contains r2
    assert_bbox_eq(inter(r1, r3), r3)
    # no intersection
    assert_equal(inter(r1, r4), None)
    # single point
    assert_bbox_eq(inter(r1, r5), bbox_from_ext(1, 1, 1, 1)) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:26,代码来源:test_transforms.py

示例13: test_dataframe_to_triples

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_array_equal [as 别名]
def test_dataframe_to_triples():
    X = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv')
    schema = [('species', 'has_sepal_length', 'sepal_length')]
    npt.assert_array_equal(dataframe_to_triples(X, schema)[0], 
                           np.array(['setosa', 'has_sepal_length', '5.1']))
    
    schema = [('species', 'has_sepal_length', 'abc')]
    try:
        dataframe_to_triples(X, schema)
    except:
        assert True
    
    schema = [('species', 'has_sepal_length', 'sepal_length')]
    try:
        dataframe_to_triples(X, schema)
    except:
        assert True 
开发者ID:Accenture,项目名称:AmpliGraph,代码行数:19,代码来源:test_model_utils.py

示例14: test_dim_dft

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_array_equal [as 别名]
def test_dim_dft(self):
        N = 16
        da = xr.DataArray(np.random.rand(N,N), dims=['x','y'],
                        coords={'x':range(N),'y':range(N)}
                         )
        npt.assert_array_equal(xrft.dft(da, dim='y', shift=False).values,
                              xrft.dft(da, dim=['y'], shift=False).values
                              )
        assert xrft.dft(da, dim='y').dims == ('x','freq_y') 
开发者ID:xgcm,项目名称:xrft,代码行数:11,代码来源:test_xrft.py

示例15: test_dft_3d_dask

# 需要导入模块: from numpy import testing [as 别名]
# 或者: from numpy.testing import assert_array_equal [as 别名]
def test_dft_3d_dask(self, dask):
        """Test the discrete Fourier transform on 3D dask array data"""
        N=16
        da = xr.DataArray(np.random.rand(N,N,N), dims=['time','x','y'],
                          coords={'time':range(N),'x':range(N),
                                  'y':range(N)}
                         )
        if dask:
            da = da.chunk({'time': 1})
            daft = xrft.dft(da, dim=['x','y'], shift=False)
            npt.assert_almost_equal(daft.values,
                                   np.fft.fftn(da.chunk({'time': 1}).values,
                                              axes=[1,2])
                                   )
            da = da.chunk({'x': 1})
            with pytest.raises(ValueError):
                xrft.dft(da, dim=['x'])
            with pytest.raises(ValueError):
                xrft.dft(da, dim='x')

            da = da.chunk({'time':N})
            daft = xrft.dft(da, dim=['time'],
                           shift=False, detrend='linear')
            da_prime = sps.detrend(da, axis=0)
            npt.assert_almost_equal(daft.values,
                                   np.fft.fftn(da_prime, axes=[0])
                                   )
            npt.assert_array_equal(daft.values,
                                   xrft.dft(da, dim='time',
                                            shift=False, detrend='linear')
                                   ) 
开发者ID:xgcm,项目名称:xrft,代码行数:33,代码来源:test_xrft.py


注:本文中的numpy.testing.assert_array_equal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。