Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

NumPy: fromiter() function

fromiter() function

The fromiter() function is used to create a new 1-dimensional array from an iterable object.

Syntax:

numpy.fromiter(iterable, dtype, count=-1)
NumPy array: fromiter() function

Version: 1.15.0

Parameter:

Name Description Required /
Optional
iterable An iterable object providing data for the array. Required
dtype The data-type of the returned array. Required
count The number of items to read from iterable. The default is -1, which means all data is read. Optional

Return value:

out : ndarray
The output array.

Example-1: NumPy.fromiter() method

>>> import numpy as np
>>> iterable = (a*a for a in range(6))
>>> np.fromiter(iterable, float)
array([  0.,   1.,   4.,   9.,  16.,  25.])

Pictorial Presentation:

NumPy array: fromiter() function

Python - NumPy Code Editor:

Previous: fromfunction()
Next: fromstring()