# Inconsistent results using SimpleITK ChangeLabelLabelMap

**URL:** https://discourse.itk.org/t/inconsistent-results-using-simpleitk-changelabellabelmap/6392
**Category:** Engineering
**Tags:** bug
**Created:** [January 15, 2024, 6:15am UTC](https://discourse.itk.org/t/inconsistent-results-using-simpleitk-changelabellabelmap/6392 "2024-01-15T06:15:03Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![drusmanbashir](https://discourse.itk.org/user_avatar/discourse.itk.org/drusmanbashir/32/3861_2.png) [@drusmanbashir](https://discourse.itk.org/u/drusmanbashir)
#### Post date: [January 15, 2024, 6:15am UTC](https://discourse.itk.org/t/inconsistent-results-using-simpleitk-changelabellabelmap/6392/1 "2024-01-15T06:15:03Z")

</div>

Hi I use SimpleITK python, and this is issue is specific to the python wrapper.

I frequently use loops to create remapping dictionary for labelmaps. However, I get an error from ITK 🙂

```auto
 in method 'ChangeLabelLabelMap', argument 2 of type 'std::map< double,double,std::less< double >,std::allocator< std::pair< double const,double > > 

```

when using loops. Below script will illustrate the issue:

```auto
img = sitk.Image([10,10], sitk.sitkLabelUInt16)

img[1,2] = 1

remapping = {x:0 for x in np.arange(1, 3)}
result = sitk.ChangeLabelLabelMap(img, remapping)

remapping2 = {1:0, 2:0}
print(remapping == remapping2)

result = sitk.ChangeLabelLabelMap(img, remapping2)
result[1,2]

```

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [January 16, 2024, 2:32pm UTC](https://discourse.itk.org/t/inconsistent-results-using-simpleitk-changelabellabelmap/6392/2 "2024-01-16T14:32:28Z")

</div>

> [@drusmanbashir](#):
>
> `result = sitk.ChangeLabelLabelMap(img, remapping)`

The issue here is that `np.arange` returns an iterable of type `numpy.in64` and not of `int`, or `float` or another type that is implicitly convertible by SWIG to the `std::map< double,double>` type. The solution is to either use the Python `range` method or explicitly do a conversion on `x` in the dictionary generator expression.
