I wrote a function which returns different outputs and I need to iteratively call the function for each element of an array (passed as an iterable).
However, I am only able to retrieve the output as a tuple and I can't figure out how to unpack each element. Here is a toy example:
def returninput(a,b,c):
return a,b,c
The following work but returns a list of tuples:
it=iter(np.linspace(1,100,100))
a=[returninput(elem, elem+1,elem+2) for elem in it]
In: a
Out: [(1.0, 2.0, 3.0),
(2.0, 3.0, 4.0),
(3.0, 4.0, 5.0),
(4.0, 5.0, 6.0),
.............
(99.0, 100.0, 101.0),
(100.0, 101.0, 102.0)]
I'd like to have a list of elements for each variable in output, so I tried:
it=iter(np.linspace(1,100,100))
a,b,c=[returninput(elem, elem+1,elem+2) for elem in it]
But I get too many values to unpack (expected 3)
.
Desired output would be:
In: a
Out: [1.0, 2.0, 3.0, 4.0,...,100]
In: b
Out: [2.0, 3.0, 4.0, 5.0,...,101]
In: c
Out: [3.0, 4.0, 5.0, 6.0,...,102]