I would like to get the following:
>>> import numpy as np
>>> import itertools
>>> a1 = np.random.randn(100)
>>> a2 = np.random.randn(100)
>>> l = [np.linspace(start=np.asscalar(min(a1[i],a2[i])), stop=np.asscalar(max(a1[i],a2[i])), num=30) for i in range(len(a1))]
However, the elements in l
are now arrays. I would like to have a list of floats. If I do
l = [np.linspace(start=np.asscalar(min(a1[i],a2[i])), stop=np.asscalar(max(a1[i],a2[i])), num=30).tolist() for i in range(len(a1))]
I get a list of lists so I would need to unpack the inner one via
>>> list(chain.from_iterable(l))
The list I have is pretty large so that I would like to get the right result from the beginning. Is there a way to achieve that or is the second step via itertools chain necessary?