当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python numpy chararray.setfield用法及代码示例


本文简要介绍 python 语言中 numpy.char.chararray.setfield 的用法。

用法:

char.chararray.setfield(val, dtype, offset=0)

将值放入由数据类型定义的字段中的指定位置。

地方进入a的字段定义为numpy.dtype和开始抵消字节到字段中。

参数

val 对象

要放置在字段中的值。

dtype 数据类型对象

放置 val 的字段的数据类型。

offset 整数,可选

字段中放置 val 的字节数。

返回

None

例子

>>> 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.]])

相关用法


注:本文由纯净天空筛选整理自numpy.org大神的英文原创作品 numpy.char.chararray.setfield。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。