numpy.matrix.setfield#
方法
- matrix.setfield(val, dtype, offset=0)#
將值放入由資料型態定義之欄位的指定位置。
將 val 放入 a 的欄位,該欄位由
dtype
定義,並從欄位開始的 offset 位元組處開始。- 參數:
- val物件
要放入欄位的值。
- dtypedtype 物件
要放入 val 的欄位的資料型態。
- offsetint,選用
要放入 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.]])