numpy.fromiter()

This function is used to create a ndarray by using an iterable object. It returns a one-dimensional ndarray object.

Syntax

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

Parameters

It accepts the following parameters.

  1. Iterable: It represents an iterable object.
  2. dtype: It represents the data type of the resultant array items.
  3. count: It represents the number of items to read from the buffer in the array.

Return

An array created by using the iterable object is returned.

Example

snippet
import numpy as np
list = [0,2,4,6]
it = iter(list)
x = np.fromiter(it, dtype = float)
print(x)
print(type(x))

Output:

Output
[0. 2. 4. 6.]
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +