Python nodes support complex numbers ?

Do the python node support complex numbers ?
I have the following error

ERROR PythonKernel                    C:\Program Files\KNIME\plugins\org.knime.python2_3.5.0.v201712011355\py\ ComplexWarning: Casting complex values to real discards the imaginary part
ERROR PythonKernel                    LookupError: No serializer extension having the id or processing python type "complex128" could be found.
ERROR Python Source        0:157      Execute failed: Connection reset

with the following example code in a python source node :

from pandas import DataFrame

column = [1+2j,2+4j]
output_table = DataFrame(column)

The code executes without issue in the code editor, but not in the workflow.

1 Like

if 2j and 4j are variables could it be that you have to explicitly address them in the code?

from pandas import DataFrame

column = [1+input_table[‘2j’],2+input_table[‘4j’]]
output_table = DataFrame(column)

kn_example_python1.knwf (17.5 KB)

2j and 4j are not variables. It is the notation for the imaginary part of a complex number in Python

-> complex

Could you provide us with an example workflow?

I found my answer :
Java (and hence knime) simply does not have a built in data type for complex numbers contrary to Python.
A workaround is simply to convert them to a string.

ComplexNumber.knwf (9.6 KB)

1 Like

ImgLib2, the library backing ImageJ and the KNIME Image Processing extension, has a ComplexType, so if you’re working with images (and Fourier transform etc.) you could possibly hand over ImgPlus objects which are a supported column type in KNIME. I’ve not tried it, though…

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.