Question about KNIME python numpy output


I am very good at Python and Tensorflow, but I am newbie of KNIME.

I have a question.

Assuming that I am using “Python source” module in KNIME.

import tensorflow as tf
from tensorflow import keras
import numpy as np
import matplotlib.pyplot as plt
fashion_mnist = keras.datasets.fashion_mnist(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()

I want to use “train_images” numpy variable as output, and the dimension is (60000, 28, 28).
However, I found that numpy cannot be used for output of “Python source” module, but only “pandas dataframe” can be used. But, my data is 3d data, so conversion (from numpy to pandas) would be tricky…

Do you have any good solution for this?

Thank you!!!

Hi @leekh3,
first of all: welcome to the KNIME Forum! Well, KNIME tables are also only 2D, so if you want to return your numpy array, what do you expect to receive on the KNIME side? The only solution I see is “flattening” the array into a Pandas data frame of the form x, y, z, value. However, with that many dimensions this only works for sparse data.
Kind regards,

Thank you for your prompt reply!!!

Okay. Then, if I flatten the array: (60000, 28, 28) ==> (60000*28, 28), is there any method
for reverse (get the original one) from KNIME native module?

Thank you.

No, I don’t think there is a native way to reverse that. You would also have to do it in python to get back an numpy array.
Kind regards

how about you save your array as a npy or npz to disk and reload it later. There might be some issues with more complex arrays but this should work.

Also, it should be possible to just save something as a pickle file.

kn_example_python_numpy_save.knwf (14.4 KB)