-
numpy.fromiter(iterable, dtype, count=-1)
-
Create a new 1-dimensional array from an iterable object.
Parameters: iterable : iterable object
An iterable object providing data for the array.
dtype : data-type
The data-type of the returned array.
count : int, optional
The number of items to read from iterable. The default is -1, which means all data is read.
Returns: out : ndarray
The output array.
Notes
Specify
count
to improve performance. It allowsfromiter
to pre-allocate the output array, instead of resizing it on demand.Examples
123>>> iterable
=
(x
*
x
for
x
in
range
(
5
))
>>> np.fromiter(iterable, np.
float
)
array([
0.
,
1.
,
4.
,
9.
,
16.
])
numpy.fromiter()

2025-01-10 15:47:30
Please login to continue.