I want to build a numpy.array (of shape (3, 2)) using numpy.fromiter
The numpy array will consist of 3 numpy arrays containing 2 floats each. These 3 arrays will be the output of a custom function but for the example I will use numpy.random.randn.
Inspired by the documentation, my code looks like:
iterable = (np.random.randn(2) for _ in range(3))
np.fromiter(iterable, float, 3)
But I get the following error that I do not understand:
ValueError: setting an array element with a sequence.
I could simply use np.array([np.random.randn(2) for _ in range(3)]) (which works as I want) but in my understanding it would be less efficient since the list is actually built