我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用numpy.testing.assert_approx_equal()。
def assert_probmatrix(mat): is_sum = mat.sum(dtype=np.float32) should_sum = mat.shape[0] assert_approx_equal(is_sum, should_sum, significant=0) [assert_approx_equal(rowsum, 1., significant=1) for rowsum in mat.sum(axis=1, dtype=np.float32)]
def test_seq(): result = seq(4.1, 5.2, 0.1) npt.assert_approx_equal(result[-1], 5.2) result = seq(1, 10, length_out=10) npt.assert_array_equal(result, range(1, 11)) with pytest.raises(ValueError): seq(1, 10, length_out=0)