# how can i use iterators in simpleITK python?

**URL:** <https://discourse.itk.org/t/how-can-i-use-iterators-in-simpleitk-python/3363>\
**Category:** Uncategorized\
**Created:** [August 5, 2020, 4:20am UTC](https://discourse.itk.org/t/how-can-i-use-iterators-in-simpleitk-python/3363 "2020-08-05T04:20:43Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)\
**Post date:** [August 5, 2020, 1:03pm UTC](https://discourse.itk.org/t/how-can-i-use-iterators-in-simpleitk-python/3363/2 "2020-08-05T13:03:35Z")

</div>

Hello @unicorn,

Similar to [the answer](https://discourse.itk.org/t/metric-to-compare-two-images-using-simpleitk/3351) to your previous question. The various similarity measures are listed in the SimpleITK documentation (one of them is normalized cross-correlation).

If you want to perform computations using all pixels, iterating is best avoided.  
We highly recommend using a broadcasting approach, applying operations to the whole image in one go, same as when working with numpy and most other Python tools (e.g. `sitk.Square(img1-img2)`).

If you are more comfortable using numpy then you can just get views of the image data and work in numpy:

```auto
arr1 = sitk.GetArrayViewFromImage(img1)
arr2 = sitk.GetArrayViewFromImage(img2)
(arr1-arr2)**2

```

---

_[View the full topic](https://discourse.itk.org/t/how-can-i-use-iterators-in-simpleitk-python/3363)._
