SciPy

numpy.obj2sctype

numpy.obj2sctype(rep, default=None)[source]

Return the scalar dtype or NumPy equivalent of Python type of an object.

Parameters:
rep : any

The object of which the type is returned.

default : any, optional

If given, this is returned for objects whose types can not be determined. If not given, None is returned for those objects.

Returns:
dtype : dtype or Python type

The data type of rep.

Examples

>>> 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'>

Previous topic

numpy.common_type

Next topic

numpy.format_parser