MCPcopy Index your code
hub / github.com/numpy/numpy / test_complex

Method test_complex

numpy/ma/tests/test_extras.py:349–391  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

347 assert_equal(a, 1.5)
348
349 def test_complex(self):
350 # Test with complex data.
351 # (Regression test for https://github.com/numpy/numpy/issues/2684)
352 mask = np.array([[0, 0, 0, 1, 0],
353 [0, 1, 0, 0, 0]], dtype=bool)
354 a = masked_array([[0, 1 + 2j, 3 + 4j, 5 + 6j, 7 + 8j],
355 [9j, 0 + 1j, 2 + 3j, 4 + 5j, 7 + 7j]],
356 mask=mask)
357
358 av = average(a)
359 expected = np.average(a.compressed())
360 assert_almost_equal(av.real, expected.real)
361 assert_almost_equal(av.imag, expected.imag)
362
363 av0 = average(a, axis=0)
364 expected0 = average(a.real, axis=0) + average(a.imag, axis=0) * 1j
365 assert_almost_equal(av0.real, expected0.real)
366 assert_almost_equal(av0.imag, expected0.imag)
367
368 av1 = average(a, axis=1)
369 expected1 = average(a.real, axis=1) + average(a.imag, axis=1) * 1j
370 assert_almost_equal(av1.real, expected1.real)
371 assert_almost_equal(av1.imag, expected1.imag)
372
373 # Test with the 'weights' argument.
374 wts = np.array([[0.5, 1.0, 2.0, 1.0, 0.5],
375 [1.0, 1.0, 1.0, 1.0, 1.0]])
376 wav = average(a, weights=wts)
377 expected = np.average(a.compressed(), weights=wts[~mask])
378 assert_almost_equal(wav.real, expected.real)
379 assert_almost_equal(wav.imag, expected.imag)
380
381 wav0 = average(a, weights=wts, axis=0)
382 expected0 = (average(a.real, weights=wts, axis=0) +
383 average(a.imag, weights=wts, axis=0) * 1j)
384 assert_almost_equal(wav0.real, expected0.real)
385 assert_almost_equal(wav0.imag, expected0.imag)
386
387 wav1 = average(a, weights=wts, axis=1)
388 expected1 = (average(a.real, weights=wts, axis=1) +
389 average(a.imag, weights=wts, axis=1) * 1j)
390 assert_almost_equal(wav1.real, expected1.real)
391 assert_almost_equal(wav1.imag, expected1.imag)
392
393 @pytest.mark.parametrize(
394 'x, axis, expected_avg, weights, expected_wavg, expected_wsum',

Callers

nothing calls this directly

Calls 3

averageFunction · 0.90
assert_almost_equalFunction · 0.90
compressedMethod · 0.45

Tested by

no test coverage detected