I have a generator that returns numpy arrays. For example sake, let it be:
import numpy as np
a = np.arange(9).reshape(3,3)
gen = (x for x in a)
Calling:
np.sum(gen)
On numpy 1.17.4:
DeprecationWarning: Calling np.sum(generator) is deprecated, and in the future will give a different result. Use np.sum(np.fromiter(generator)) or the python sum builtin instead.
Trying to refactor the above:
np.sum(np.fromiter(gen, dtype=np.ndarray))
I get:
ValueError: cannot create object arrays from iterator
What is wrong in the above statement?