-
Notifications
You must be signed in to change notification settings - Fork 481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
calling sitk function with int argument does not work with Python 3 #204
Comments
@haarburger, thanks for the heads up! This conversion was giving us trouble before (and fixed it by casting to 'int', but apparently doesn't work for python 3). We'll look into it to make it python 3 compatible. If you find a solution in the meantime, we'd welcome your contribution. |
|
@blowekamp Would it make sense to improve the wrapping layer to directly understand numpy array as parameter ? |
I would try using an unsigned integer type for the numpy array.
`np.array([1, 2, 3], dtype='uint32')`
The Swig wrapping layer does understand numpy arrays. It does not implicitly convert numpy signed integer arrays to unsigned array types.
… On Feb 17, 2017, at 5:40 PM, Jean-Christophe Fillion-Robin ***@***.***> wrote:
rif = sitk.ResampleImageFilter()
rif.SetSize(np.array([1, 2, 3], dtype='int'))
TypeError: in method 'ResampleImageFilter_SetSize', argument 2 of type 'std::vector< uint32_t,std::allocator< uint32_t > > const &'
np.array([1, 2, 3], dtype='int').tolist() does the trick. I'll create a PR shortly.
@blowekamp Would it make sense to improve the wrapping layer to directly understand numpy array as parameter ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@blowekamp Actually, |
@haarburger, did you also try 'uint'? |
Yes, doesn't work either. |
I will have to look into the further. Can you please create a SimpleITK Issue, and include the SimpleITK version, OS, Python Distribute, etc.. where the problem has occurred? Have you checked if SimpleITK 1.0rc1 has the same issue? |
@blowekamp the problem also occurs with 1.0rc1. |
Resolved by #205 |
@jcfr When using Python 3.5, resampling as implemented in imageoperations.py#L187 does not work.
sitk.ResampleImageFilter accepts uint32_t arguments. In Python 2.7 this works fine with passing
np.int
. However, in Python 3 this is not working anymore.Example:
Which numpy type whould result in uint32_t for both python 2 and 3? With
np.uint32
I get the same error.Converting the array to python
int
witharr = [int(x) for x in arr]
resolves the issue but is ugly...The text was updated successfully, but these errors were encountered: