numpy.ndarray.dtype#

属性

ndarray.dtype#

数组元素的**数据类型**。

警告

不建议设置 arr.dtype,并且将来可能会弃用。设置将替换 dtype 而不修改内存(另请参阅 ndarray.viewndarray.astype)。

参数:
None
返回:
dnumpy 数据类型对象

另请参阅

ndarray.astype

将数组中的值强制转换为新的数据类型。

ndarray.view

创建对同一数据的视图,但使用不同的数据类型。

numpy.dtype

示例

>>> import numpy as np
>>> x = np.arange(4).reshape((2, 2))
>>> x
array([[0, 1],
       [2, 3]])
>>> x.dtype
dtype('int64')   # may vary (OS, bitness)
>>> isinstance(x.dtype, np.dtype)
True