MCPcopy
hub / github.com/numpy/numpy / assert_array_almost_equal

Function assert_array_almost_equal

numpy/testing/_private/utils.py:1133–1231  ·  view source on GitHub ↗

Raises an AssertionError if two objects are not equal up to desired precision. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point

(actual, desired, decimal=6, err_msg='',
                              verbose=True)

Source from the content-addressed store, hash-verified

1131
1132
1133def assert_array_almost_equal(actual, desired, decimal=6, err_msg='',
1134 verbose=True):
1135 """
1136 Raises an AssertionError if two objects are not equal up to desired
1137 precision.
1138
1139 .. note:: It is recommended to use one of `assert_allclose`,
1140 `assert_array_almost_equal_nulp` or `assert_array_max_ulp`
1141 instead of this function for more consistent floating point
1142 comparisons.
1143
1144 The test verifies identical shapes and that the elements of ``actual`` and
1145 ``desired`` satisfy::
1146
1147 abs(desired-actual) < 1.5 * 10**(-decimal)
1148
1149 That is a looser test than originally documented, but agrees with what the
1150 actual implementation did up to rounding vagaries. An exception is raised
1151 at shape mismatch or conflicting values. In contrast to the standard usage
1152 in numpy, NaNs are compared like numbers, no assertion is raised if both
1153 objects have NaNs in the same positions.
1154
1155 Parameters
1156 ----------
1157 actual : array_like
1158 The actual object to check.
1159 desired : array_like
1160 The desired, expected object.
1161 decimal : int, optional
1162 Desired precision, default is 6.
1163 err_msg : str, optional
1164 The error message to be printed in case of failure.
1165 verbose : bool, optional
1166 If True, the conflicting values are appended to the error message.
1167
1168 Raises
1169 ------
1170 AssertionError
1171 If actual and desired are not equal up to specified precision.
1172
1173 See Also
1174 --------
1175 assert_allclose: Compare two array_like objects for equality with desired
1176 relative and/or absolute precision.
1177 assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal
1178
1179 Examples
1180 --------
1181 the first assert does not raise an exception
1182
1183 >>> np.testing.assert_array_almost_equal([1.0,2.333,np.nan],
1184 ... [1.0,2.333,np.nan])
1185
1186 >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan],
1187 ... [1.0,2.33339,np.nan], decimal=5)
1188 Traceback (most recent call last):
1189 ...
1190 AssertionError:

Callers 15

test_randMethod · 0.90
test_rand_singletonMethod · 0.90
test_randnMethod · 0.90
test_random_sampleMethod · 0.90
test_betaMethod · 0.90
test_chisquareMethod · 0.90
test_dirichletMethod · 0.90
test_exponentialMethod · 0.90
test_fMethod · 0.90
test_gammaMethod · 0.90
test_gumbelMethod · 0.90

Calls 1

assert_array_compareFunction · 0.70

Tested by 15

test_randMethod · 0.72
test_rand_singletonMethod · 0.72
test_randnMethod · 0.72
test_random_sampleMethod · 0.72
test_betaMethod · 0.72
test_chisquareMethod · 0.72
test_dirichletMethod · 0.72
test_exponentialMethod · 0.72
test_fMethod · 0.72
test_gammaMethod · 0.72
test_gumbelMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…