Python Scripting error with Pandas

Hello,

When I’m running the following code in the Python Console, it works well.

def convert_output_to_df(output_vector):
“”“Converts the result of get_output_vector function into a pandas Dataframe”""
df = pd.DataFrame(columns=[‘Class’, ‘Value’])
for item in output_vector:
df_eph = pd.DataFrame(item, columns=[‘Class’, ‘Value’])
df = pd.concat([df, df_eph])
return df

# Load image
image = Image.open(file)
image = np.asarray(image)
# Look for associated GT and load it
assoc_gt = gt_dir + file.split('\\')[-1]
gt = Image.open(assoc_gt)
gt = gt.convert('1')
gt = np.asarray(gt)

# Get padded image
pad_img = pad_image(image, cut_size, neigh_size)
# Get output for this image
output = get_output_vector(pad_img, gt, cut_size, neigh_size, threshold)
# Add result for this image in the global list
res.append(output)

output_table = convert_output_to_df(res)

When executing the node I get the following error:

Execute failed: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Any tips ?

Thanks
Best
Jerome

Hello,

I finally found my error : numpy conversion error to DataFrame. You have to convert to a list first.

Maybe a bug in KNIME ?

Have a great day!
Best
Jerome

2 Likes

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