The fromiter() function in Python simply creates a new 1D (one-dimensional) array from an iterable object passed to the object.
numpy.fromiter(iter, dtype)
The fromiter() function takes the following parameter values:
iter: This is the iterable object representing the data for the array.dtype: This is the data type of the desired array.The fromiter() function returns an output 1D array.
import numpy as np# Creating an iterable objectmyiterable = (i * i for i in range(3))# Implementing the numpy.fromiter() functionmyarray = np.fromiter(myiterable, float)print(myarray)
numpy module.myiterable.fromiter() function on the iterable array myiterable and assign the output to a myarray variable.myarray, the new 1D array.