w3resource

NumPy Data type: sctype2char() function

numpy.sctype2char() function

The sctype2char() function is used to get the string representation of a scalar dtype.

Version: 1.15.0

Syntax:

numpy.sctype2char(sctype)

Parameter:

Name Description Required /
Optional
sctype : scalar dtype or object If a scalar dtype, the corresponding string character is returned. If an object, sctype2char tries to infer its scalar type and then return the corresponding string character. Required

Return value:

typechar : str - The string character corresponding to the scalar type.

Raises:

ValueError - If sctype is an object for which the type can not be inferred.

Example: numpy.sctype2char() function

>>> import numpy as np
>>> for sctype in [np.int32, float, complex, np.string_, np.ndarray]:
	print(np.sctype2char(sctype))
	
l
d
D
S
O

Example: numpy.sctype2char() function

>>> import numpy as np
>>> a = np.array([1., 2-1.j])
>>> np.sctype2char(a)
'D'
>>> np.sctype2char(list)
'O'
>>>

Python Code Editor:

Previous: Miscellaneous typename()
Next: mintypecode()



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/numpy/data-type-routines/sctype2char.php