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)

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:

Python - NumPy Code Editor:
Previous: fromfunction()
Next: fromstring()
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises