Learn | NEPs | User Guide | API reference | Building from source | Development | Release notes | NumPy’s module structure | Array objects | The N-dimensional array (ndarray) | Scalars | Data type objects (dtype) | Data type promotion in NumPy | Iterating over arrays | Standard array subclasses | Masked arrays | The array interface protocol | Datetimes and timedeltas | Universal functions (ufunc) | Routines and objects by topic | Typing (numpy.typing) | NumPy C-API | Array API standard compatibility | CPU/SIMD optimizations | Thread Safety | Global Configuration Options | NumPy security | Testing guidelines
method
ndarray.setfield(val, dtype, offset=0)
Put a value into a specified place in a field defined by a data-type.
Place val into a’s field defined by
and beginning offset bytes into the field.
Parameters:valobjectValue to be placed in field.
dtypedtype objectData-type of the field in which to place val.
offsetint, optionalThe number of bytes into the field at which to place val.
Returns:NoneExamples
>>> importnumpyasnp>>> 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)>>> xarray([[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)>>> xarray([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]])