numpy.matrix.setfield#
method
- matrix.setfield(val, dtype, offset=0)#
将一个值放入由数据类型定义的字段中的指定位置.
将 val 放入 a 的字段中,该字段由
dtype定义,并从字段开始 offset 个字节.- 参数:
- valobject
要放入字段中的值.
- dtypedtype object
用于放置 val 的字段的数据类型.
- offsetint, optional
将 val 放入字段中的字节数.
- 返回:
- None
参见
示例
>>> 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.]])