# How to capture multiple transformations while using timeit

**URL:** https://discourse.itk.org/t/how-to-capture-multiple-transformations-while-using-timeit/5589
**Category:** Beginner Questions
**Tags:** registration, python, simpleitk
**Created:** [December 22, 2022, 11:11am UTC](https://discourse.itk.org/t/how-to-capture-multiple-transformations-while-using-timeit/5589 "2022-12-22T11:11:59Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![debapriya](https://discourse.itk.org/letter_avatar_proxy/v4/letter/d/bc79bd/32.png) [@debapriya](https://discourse.itk.org/u/debapriya)
#### Post date: [December 22, 2022, 11:11am UTC](https://discourse.itk.org/t/how-to-capture-multiple-transformations-while-using-timeit/5589/1 "2022-12-22T11:11:59Z")

</div>

Hello,

I am running intensity based image registration using SimpleITK. I am using `timeit` command, with 7 repetitions, to find out the mean time required by the registration process.

I also want to find out the mean `final_transformation` of the 7 iterations of `timeit`. How can I do that?

---

<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: [December 22, 2022, 2:33pm UTC](https://discourse.itk.org/t/how-to-capture-multiple-transformations-while-using-timeit/5589/2 "2022-12-22T14:33:50Z")

</div>

Hello @debapriya,

This is not an ITK/SimpleITK question, it is about the `timeit` magic from ipython, so not the correct forum for asking such a question.

Having said that, the answer is that you **cannot** achieve what you want using the `timeit` magic because it discards the output and you need to retain outputs across iterations. You will need to implement your own, something along the lines of:

```auto
import random
import time

num_iterations = 3 

res_list = []
times_list = []
for i in range(num_iterations):
  start_time = time.time()
  registration_result = random.randint(0,10)
  end_time = time.time()
  res_list.append(registration_result)
  times_list.append(end_time - start_time)

```

Back to SimpleITK/ITK, be careful when computing the average of multiple transformations. This is usually not the naive mean (see [this paper on averaging rotations](https://lcvmwww.epfl.ch/publications/data/articles/63/Means_and_Averaging_in_the_Group_of_Rotations.pdf)).
