0 votes
in Python by
Explain numpy.fromiter() in Python

1 Answer

0 votes
by
numpy.fromiter() in Python The fromiter() function of Python numpy class creates a ndarray by using an iterable object. It returns a one-dimensional ndarray object. Syntax

numpy.fromiter(iterable, dtype, count=-1)

Parameter The numpy.frombuffer() method consists of three parameters, which are as follows:

Iterable: This parameter represents an iterable object.

dtype: It represents the data type of the resultant array items.

count: This functiondepicts the number of items to read from the buffer in the specified array.

Return This function returns an array created by using the iterable object. Example 1

# Python Programming giving an example for

# numpy.fromiter() function

importnumpy as numpy

my_list = [0,2,4,6]

it = iter(my_list)

n = numpy.fromiter(it, dtype = float)

print(n)

print(type(n))

Output

[ 0.  2.  4.  6.]

<class 'numpy.ndarray'>

Related questions

0 votes
asked May 19, 2022 in Python by john ganales
0 votes
asked May 19, 2022 in Python by john ganales
...