numpy.ndarray.getfield()函數以給定類型返回給定數組的字段。
用法: numpy.ndarray.getfield(dtype, offset=0)
參數:
dtype :[str或dtype]視圖的dtype大小不能大於數組本身的大小。
offset:[int]開始元素視圖之前要跳過的字節數。
Return :以給定類型返回給定數組的字段。
代碼1:
# Python program explaining
# numpy.ndarray.getfield() function
# importing numpy as geek
import numpy as geek
x = geek.diag([1.+1.j]*2)
gfg = x.getfield(geek.float64)
print(gfg)
輸出:
[[ 1. 0.] [ 0. 1.]]
代碼2:
# Python program explaining
# numpy.ndarray.getfield() function
# importing numpy as geek
import numpy as geek
x = geek.diag([2.+2.j]*2)
gfg = x.getfield(geek.float64, offset = 8)
print(gfg)
輸出:
[[ 2. 0.] [ 0. 2.]]
相關用法
- Python numpy.cov()用法及代碼示例
- Python numpy.ix_()用法及代碼示例
- Python numpy.ma.notmasked_edges()用法及代碼示例
- Python numpy.ma.flatnotmasked_edges()用法及代碼示例
- Python numpy.nanmean()用法及代碼示例
- Python numpy.ma.flatnotmasked_contiguous()用法及代碼示例
- Python Numpy recarray.dot()用法及代碼示例
- Python numpy.ma.mask_or()用法及代碼示例
- Python numpy.ma.make_mask_none()用法及代碼示例
- Python numpy.ma.mask_cols()用法及代碼示例
- Python numpy.ma.clump_unmasked()用法及代碼示例
- Python Numpy recarray.mean()用法及代碼示例
- Python numpy.ma.clump_masked()用法及代碼示例
注:本文由純淨天空篩選整理自sanjoy_62大神的英文原創作品 Numpy ndarray.getfield() function | Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。