numpy.fromiter()函數從可迭代對象創建新的一維數組。
用法:numpy.fromiter(iterable, dtype, count = -1)
參數:
iterable:[可迭代對象]為數組提供數據的可迭代對象。
dtype:[數據類型]返回數組的數據類型。
count:[int,可選]要讀取的項目數。
Returns:[ndarray]輸出數組。
代碼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)
輸出:
[ 0 1 8 27]
代碼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)
輸出:
[ 0. 1. 4. 9. 16. 25.]
相關用法
- Python numpy.cov()用法及代碼示例
- Python numpy.ma.where()用法及代碼示例
- Python numpy.ix_()用法及代碼示例
- Python numpy.char.add()用法及代碼示例
- Python numpy.ma.mask_rowcols()用法及代碼示例
- Python numpy.ma.mask_cols()用法及代碼示例
- Python numpy.ma.make_mask_none()用法及代碼示例
- Python numpy.ma.clump_unmasked()用法及代碼示例
- Python numpy.ma.make_mask()用法及代碼示例
- Python numpy.ma.mask_or()用法及代碼示例
- Python numpy.ma.flatnotmasked_contiguous()用法及代碼示例
- Python numpy.ma.flatnotmasked_edges()用法及代碼示例
- Python numpy.ma.notmasked_edges()用法及代碼示例
- Python numpy.ma.clump_masked()用法及代碼示例
- Python Numpy recarray.any()用法及代碼示例
- Python Numpy recarray.all()用法及代碼示例
- Python numpy.ma.append()用法及代碼示例
注:本文由純淨天空篩選整理自sanjoy_62大神的英文原創作品 numpy.fromiter() function – Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。