📜  numpy.fromiter()函数– Python

📅  最后修改于: 2022-05-13 01:55:14.896000             🧑  作者: Mango

numpy.fromiter()函数– Python

numpy.fromiter()函数从可迭代对象创建一个新的一维数组。

代码#1:

Python3
# Python program explaining
# numpy.fromiter() function 
             
# importing numpy as geek 
import numpy as geek
  
iterable = (x * x*x for x in range(4))
  
gfg = geek.fromiter(iterable, int)
  
print (gfg)


Python3
# Python program explaining
# numpy.fromiter() function 
             
# importing numpy as geek 
import numpy as geek
  
iterable = (x * x for x in range(6))
  
gfg = geek.fromiter(iterable, float)
  
print (gfg)


输出 :

代码#2:

Python3

# Python program explaining
# numpy.fromiter() function 
             
# importing numpy as geek 
import numpy as geek
  
iterable = (x * x for x in range(6))
  
gfg = geek.fromiter(iterable, float)
  
print (gfg)

输出 :