numpy.recarray.setfield#
方法
- recarray.setfield(val, dtype, offset=0)#
将值放入由数据类型定义的字段的指定位置。
将 val 放入由
dtype
定义的、从字段起始处偏移 offset 字节的 a 字段中。- 参数:
- val对象
要放入字段中的值。
- dtypedtype 对象
要放入 val 的字段的数据类型。
- offset整型, 可选
将 val 放入字段中的字节偏移量。
- 返回:
- 无
另请参阅
示例
>>> import numpy as np >>> x = np.eye(3) >>> x.getfield(np.float64) array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]) >>> x.setfield(3, np.int32) >>> x.getfield(np.int32) array([[3, 3, 3], [3, 3, 3], [3, 3, 3]], dtype=int32) >>> x array([[1.0e+000, 1.5e-323, 1.5e-323], [1.5e-323, 1.0e+000, 1.5e-323], [1.5e-323, 1.5e-323, 1.0e+000]]) >>> x.setfield(np.eye(3), np.int32) >>> x array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])