0

I want to create 2d numpy array from generator function. how to return the value as numpy array element so that I can create numpy array.

import numpy

def gen_num_py():
    yield [4287053, 19801222, 19881222]
    yield [4287054, 19801223, 19881223]
    yield [4287055, 19801224, 19881224]

a = numpy.fromiter(gen_num_py(), int)

this gives an erro (obviously)

ValueError: setting an array element with a sequence.

the question is how to create numpy array element in yield statement so that this works to give result:

array([[4287053, 19801222, 19881222],
       [4287054, 19801223, 19881223],
       [4287055, 19801224, 19881224]])
Rahul
  • 10,830
  • 4
  • 53
  • 88

0 Answers0