numpy.char.chararray.setfield#
方法
- char.chararray.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.]])