code: def test_parcel_exclude():
      # Test excluding from parcels
      data = np.arange(5)
      ps = gen.parcels(data, (1, 3))
      assert_array_equal(next(ps), [False, True, False, False, False])
      assert_array_equal(next(ps), [False, False, False, True, False])
      pytest.raises(StopIteration, next, ps)
      ps = gen.parcels(data, (1, 3), exclude=(1,))
      assert_array_equal(next(ps), [False, False, False, True, False])
      pytest.raises(StopIteration, next, ps)
      ps = gen.parcels(data, (1, 3), exclude=(3,))
      assert_array_equal(next(ps), [False, True, False, False, False])
      pytest.raises(StopIteration, next, ps)
      ps = gen.parcels(data, (1, 3), exclude=(3, 1))
      pytest.raises(StopIteration, next, ps)
      # Test that two element exclude works
      ps = gen.parcels(data, (1, 3, 4), exclude=(1, 4))
      assert_array_equal(next(ps), [False, False, False, True, False])
      pytest.raises(StopIteration, next, ps)
      # Also as np.array
      ps = gen.parcels(data, (1, 3, 4), exclude=np.array((1, 4)))
      assert_array_equal(next(ps), [False, False, False, True, False])
      pytest.raises(StopIteration, next, ps)
      # Test that parcels continue to be returned in sorted order
      rng = np.random.RandomState(42)
      data = rng.normal(size=(10,))
      uni = np.sort(np.unique(data))  # Should already be sorted in fact
      values = [
          np.mean(data[p])  # should be scalar anyway
          for p in gen.parcels(data, exclude=uni[0:2])
      ]
      assert_array_equal(values, uni[2:])
  
file_path: nipy/nipy/core/utils/tests/test_generators.py
imports: import numpy
  import pytest
  from numpy.testing import assert_almost_equal, assert_array_equal
  from ...api import slice_generator, write_data
  from ..None import generators
label_desc: Use image node_id 6 for calling a global function with example usage: test_parcel_exclude() without return types