# Error message may need rephrasing

**URL:** <https://discourse.itk.org/t/error-message-may-need-rephrasing/5814>\
**Category:** Community\
**Tags:** documentation, python\
**Created:** [March 20, 2023, 4:10pm UTC](https://discourse.itk.org/t/error-message-may-need-rephrasing/5814 "2023-03-20T16:10:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![edgar](https://discourse.itk.org/letter_avatar_proxy/v4/letter/e/b487fb/32.png) [@edgar](https://discourse.itk.org/u/edgar)\
**Post date:** [March 20, 2023, 4:10pm UTC](https://discourse.itk.org/t/error-message-may-need-rephrasing/5814/1 "2023-03-20T16:10:45Z")

</div>

Hi! I found that doing this:

```auto
DisplacementFieldNumpy = np.ones(
    (3, 4, 100, 100))
PyBuffer = itk.PyBuffer[VectorImageType]
DisplacementField = PyBuffer.GetImageFromArray(DisplacementFieldNumpy)

```

yields

```auto
RuntimeError: Size mismatch of image and Buffer.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "<string>", line 17, in __PYTHON_EL_eval
File "/home/edgar/.local/lib/python3.10/site-packages/itk/itkPyBufferPython.py", line 11790, in GetImageFromArray
imageView = itkPyBufferIVF33.GetImageViewFromArray(ndarr, is_vector, need_contiguous=False)
File "/home/edgar/.local/lib/python3.10/site-packages/itk/itkPyBufferPython.py", line 11760, in GetImageViewFromArray
imgview = itkPyBufferIVF33._GetImageViewFromArray(ndarr, ndarr.shape[::-1], 1)
SystemError: <built-in function itkPyBufferIVF33__GetImageViewFromArray> returned a result with an exception set

```

If the first line is changed to

```auto
DisplacementFieldNumpy = np.ones(
    (len(vti.dimensions), nz, 100, 100), dtype=np.float32)

```

the rest works.

The message should probably be one of those which tell people that their data type is wrong.

Python 3.10.10  
Numpy 1.24.2

From pip:  
itk 5.3.0  
itk-core 5.3.0  
itk-elastix 0.15.0  
itk-filtering 5.3.0  
itk-io 5.3.0  
itk-meshtopolydata 0.10.0  
itk-minimalpathextraction 1.2.4  
itk-numerics 5.3.0  
itk-registration 5.3.0  
itk-segmentation 5.3.0  
itk-strain 0.3.6  
itk-tubetk 1.3.4  
itkwidgets 0.32.5  
numpy 1.24.2

Thank you for ITK!

---

<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:** [April 4, 2023, 1:00pm UTC](https://discourse.itk.org/t/error-message-may-need-rephrasing/5814/2 "2023-04-04T13:00:42Z")

</div>

Hi @edgar ,

Thanks for the feedback!

Yes, interpreting that error message requires understanding that `VectorImageType` requested does not match the NumPy type passed. `F` (float) here corresponds to `np.float32`. `D` (double) corresponds to `np.float64`, which is the default for `np.ones`.

More information can be found here:

[https://itkpythonpackage.readthedocs.io/en/master/Quick\_start\_guide.html#itk-python-types](https://itkpythonpackage.readthedocs.io/en/master/Quick_start_guide.html#itk-python-types)

We can also call `itk.image_from_array` instead of `PyBuffer` directly. In this case, this would be:

```python
DisplacementFieldNumpy = np.ones(
    (3, 4, 100, 100))
DisplacementField = itk.image_from_array(DisplacementFieldNumpy, ttype=VectorImageType)

```

Hope this helps,  
Matt

---

<div class="post-metadata">

**Author:** ![edgar](https://discourse.itk.org/letter_avatar_proxy/v4/letter/e/b487fb/32.png) [@edgar](https://discourse.itk.org/u/edgar)\
**Post date:** [July 5, 2023, 12:19am UTC](https://discourse.itk.org/t/error-message-may-need-rephrasing/5814/3 "2023-07-05T00:19:59Z")

</div>

Thanks, Matt. Sorry for the delay.
