Q:

Write a NumPy program to create an array using generator function that generates 15 integers

0

Write a NumPy program to create an array using generator function that generates 15 integers.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np
def generate():
   for n in range(15):
       yield n
nums = np.fromiter(generate(),dtype=float,count=-1)
print("New array:")
print(nums)
Sample Output:
New array:
[ 0.  1.  2.  3.  4.  5.  6.  7.  8.  9. 10. 11. 12. 13. 14.]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now