# How to use NumericTraits in itk python binding

**URL:** https://discourse.itk.org/t/how-to-use-numerictraits-in-itk-python-binding/1689
**Category:** Beginner Questions
**Created:** [March 20, 2019, 4:01pm UTC](https://discourse.itk.org/t/how-to-use-numerictraits-in-itk-python-binding/1689 "2019-03-20T16:01:42Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![asertyuio](https://discourse.itk.org/letter_avatar_proxy/v4/letter/a/e68b1a/32.png) [@asertyuio](https://discourse.itk.org/u/asertyuio)
#### Post date: [March 20, 2019, 4:01pm UTC](https://discourse.itk.org/t/how-to-use-numerictraits-in-itk-python-binding/1689/1 "2019-03-20T16:01:42Z")

</div>

I’m using `itk.GetImageViewFromArray(image)` to view an np image as itk image.  
How to get the type of pixel, and get information about it using NumericTraits ?

In C++ I was using for example `itk::NumericTraits<PixelType>::max()`, but with python I don’t see how to do it…  
Thanks!

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [March 20, 2019, 6:00pm UTC](https://discourse.itk.org/t/how-to-use-numerictraits-in-itk-python-binding/1689/2 "2019-03-20T18:00:38Z")

</div>

Hi Yann,

For the `itk.Image`, the Python [`type`](https://docs.python.org/3.7/library/functions.html#type) built-in function can be used to inspect the type.

```auto
print(type(image))

```

For `numpy.array`, inspect the `dtype` attribute:

```python
print(array.dtype)

```

To get the template parameters for an `itk` object, use, `itk.template`, e.g.:

```auto
>>> itk.template(image)
(<itkTemplate itk::Image>, (itkRGBPixelPython.itkRGBPixelUC, 2))

```

The pixel type can be re-used with the wrapped `NumericTraits` class:

```auto
print(itk.NumericTraits[itk.template(image)[1][0]].max())

```

HTH,  
Matt

---

<div class="post-metadata">

### Author: ![asertyuio](https://discourse.itk.org/letter_avatar_proxy/v4/letter/a/e68b1a/32.png) [@asertyuio](https://discourse.itk.org/u/asertyuio)
#### Post date: [March 20, 2019, 6:39pm UTC](https://discourse.itk.org/t/how-to-use-numerictraits-in-itk-python-binding/1689/3 "2019-03-20T18:39:03Z")

</div>

Thanks Matt, I wouldn’t get that by myself !
