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