# Finding the maximum value of displacement fields using python

**URL:** <https://discourse.slicer.org/t/finding-the-maximum-value-of-displacement-fields-using-python/4311>\
**Category:** Support\
**Created:** [October 7, 2018, 6:20am UTC](https://discourse.slicer.org/t/finding-the-maximum-value-of-displacement-fields-using-python/4311 "2018-10-07T06:20:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aseman](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@aseman](https://discourse.slicer.org/u/aseman)\
**Post date:** [October 7, 2018, 6:20am UTC](https://discourse.slicer.org/t/finding-the-maximum-value-of-displacement-fields-using-python/4311/1 "2018-10-07T06:20:52Z")

</div>

Operating system: windows 10  
Slicer version: 4.8.1  
Hi 3D slicer experts and all users  
I work with 3D slicer, but I am unfamiliar with python, and now I am learning it. I calculated the displacement fields for a specific segment (eg, lung), and as we know these vectors include components in 3 directions (RAS).  
1- I want to find the value of these vectors ( Di = ( Ri2 + Ai2 + Si2 )0.5 )  
, then find the maximum among these values Di (Di max) .  
2- If we consider for each components of R, A, S ;3 variables P, Q, N ; then what is the maximum value of each variables (eg, Pi max , Qi max , Ni max)?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 7, 2018, 4:25pm UTC](https://discourse.slicer.org/t/finding-the-maximum-value-of-displacement-fields-using-python/4311/2 "2018-10-07T16:25:16Z")

</div>

You can use [arrayFromGridTransform](https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html#slicer.util.arrayFromGridTransform) to get displacement values as a numpy array and you can use basic numpy functions to compute magnitude (norm) of the vectors and find maxima.

You can also convert any transform to a volume node containing displacement field vectors or magnitudes and use arrayFromVolume to get numpy array.
