- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Return the scalar dtype or NumPy equivalent of Python type of an object
To return the scalar dtype or NumPy equivalent of Python type of an object, use the numpy.obj2sctype() method. The 1st parameter is the object of which the type is returned The default parameter, if given, is returned for objects whose types cannot be determined. If not given, None is returned for those objects.
Steps
At first, import the required library −
import numpy as np
To return the scalar dtype or NumPy equivalent of Python type of an object, use the numpy.obj2sctype() method −
print("Using the obj2sctype() method in Numpy
")
Checking for int −
print("Result...",np.obj2sctype(np.array([45, 89]))) print("Result...",np.obj2sctype(np.array([389, 7985])))
Checking for float −
print("Result...",np.obj2sctype(np.float32)) print("Result...",np.obj2sctype(np.float64)) print("Result...",np.obj2sctype(np.array([5., 25., 40.])))
Checking for complex −
print("Result...",np.obj2sctype(np.array([5.6j]))
Example
import numpy as np # To return the scalar dtype or NumPy equivalent of Python type of an object, use the numpy.obj2sctype() method. # The 1st parameter is the object of which the type is returned # The default parameter, if given, is returned for objects whose types cannot be determined. # If not given, None is returned for those objects. print("Using the obj2sctype() method in Numpy
") # checking for int print("Result...",np.obj2sctype(np.array([45, 89]))) print("Result...",np.obj2sctype(np.array([389, 7985]))) # checking for float print("Result...",np.obj2sctype(np.float32)) print("Result...",np.obj2sctype(np.float64)) print("Result...",np.obj2sctype(np.array([5., 25., 40.]))) # checking for complex print("Result...",np.obj2sctype(np.array([5.6j])))
Output
Using the obj2sctype() method in Numpy Result... <class 'numpy.int64'> Result... <class 'numpy.int64'> Result... <class 'numpy.float32'> Result... <class 'numpy.float64'> Result... <class 'numpy.float64'> Result... <class 'numpy.complex128'>
Advertisements