import numpy as np
def gen_c():
c = np.ones(5, dtype=int)
j = 0
t = 10
while j < t:
c[0] = j
yield c.tolist()
j += 1
# What I did:
# res = np.array(list(gen_c())) <-- useless allocation of memory
# this line is what I'd like to do and it's killing me
res = np.fromiter(gen_c(), dtype=int) # dtype=list ?
The error said ValueError: setting an array element with a sequence.
This is a very stupid piece of code. I'd like to create an array of list(finally a 2D array) from a generator...
Although I searched everywhere, I still cannot figure out how to make it work.