I’m trying to iterate over two fields with different lengths
def func(subject_id,x):
return {“id”:subject_id, “x2”:x**2, “x”:x}funcnode = MapNode(Function(input_names=[“subject_id”,“x”],output_names=[“subjectdict”],function=func), name=“funcnode”, iterfield=[“subject_id”,“x”])
funcnode.inputs.subject_id = [“01”,“02”]
funcnode.inputs.x = [2,4,6,8]funcnode.run()
ValueError: All iterfields of a MapNode have to have the same length.
I understand why I’m getting the error, but was wondering if there is way around this to get the following result list?
out = [{“id”:“01”, “x2”:4, “x”:2},
{“id”:“01”, “x2”:16, “x”:4},
{“id”:“01”, “x2”:36, “x”:6},
{“id”:“01”, “x2”:64, “x”:8}
{“id”:“02”, “x2”:4, “x”:2},
{“id”:“02”, “x2”:16, “x”:4},
{“id”:“02”, “x2”:36, “x”:6},
{“id”:“02”, “x2”:64, “x”:8}]