numpy.ndarray.setfield()函數將值放入由數據類型定義的字段中的指定位置。將val放入dtype定義的字段中,並將起始偏移量字節放入該字段中。
用法: numpy.ndarray.setfield(val, dtype, offset=0)
參數:
val :[對象]放置在字段中的值。
dtype :[dtype object]放置val的字段的數據類型。
offset:[int,可選]放置val的字段中的字節數。
Return :沒有。
代碼1:
# Python program explaining
# numpy.ndarray.setfield() function
# importing numpy as geek
import numpy as geek
arr = geek.eye(4)
arr.setfield(4, geek.int32)
gfg = arr.getfield(geek.int32)
print(gfg)
輸出:
[[4 4 4 4] [4 4 4 4] [4 4 4 4] [4 4 4 4]]
代碼2:
# Python program explaining
# numpy.ndarray.setfield() function
# importing numpy as geek
import numpy as geek
arr = geek.eye(2)
arr.setfield(2, geek.int32)
gfg = arr.getfield(geek.int32)
print(gfg)
輸出:
[[2 2] [2 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.setfield() function | Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。