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()
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework