numpy.obj2sctype

numpy.obj2sctype(rep, default=None)[源代码]

返回对象的标量数据类型或与python类型等效的numpy类型。

参数
rep任何

返回类型的对象。

default任何,可选

如果给定,则对于无法确定其类型的对象返回该值。如果未给定,则不会为这些对象返回任何值。

返回
dtypedtype或python类型

的数据类型 rep .

实例

>>> np.obj2sctype(np.int32)
<class 'numpy.int32'>
>>> np.obj2sctype(np.array([1., 2.]))
<class 'numpy.float64'>
>>> np.obj2sctype(np.array([1.j]))
<class 'numpy.complex128'>
>>> np.obj2sctype(dict)
<class 'numpy.object_'>
>>> np.obj2sctype('string')
>>> np.obj2sctype(1, default=list)
<class 'list'>