w3resource logo
Python Exercises

Python NumPy: Create a numpy array of 10 integers from a generator

Python NumPy: Array Object Exercise-85 with Solution

Write a Python program to create a numpy array of 10 integers from a generator.

Sample Solution:-

Python Code:

import numpy as np
iterable = (x for x in range(10))
print(np.fromiter(iterable, np.int))

Sample Output:

[0 1 2 3 4 5 6 7 8 9]

Python Code Editor:

import numpy as np
iterable = (x for x in range(10))
print(np.fromiter(iterable, np.int))

Improve this sample solution and post your code through Disqus