numpy.recarray.setfield

方法

recarray.setfield(val, dtype, offset=0)

将值放入由数据类型定义的字段中的指定位置。

地点 val 进入之内 a 的字段由定义 dtype 开始 offset 字段中的字节。

参数
val对象

要放置在字段中的值。

dtypedType对象

要放置的字段的数据类型 val .

offset可选的

字段中要放置的字节数 val .

返回
没有

参见

getfield

实例

>>> 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.]])