- 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 string representation of a scalar dtype in Python
To return the string representation of a scalar dtype, use the sctype2char() method in Python Numpy. The 1st argument, 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.
Steps
At first, import the required library −
import numpy as np
The string representation of a scalar type −
for i in [np.int32, np.double, np.complex_, np.string_, np.ndarray]: print(np.sctype2char(i))
Return the string representation of int types −
print("\nThe string representation of int types...") for j in [np.int16, np.int32,np.int64]: print(np.sctype2char(j))
Return the string representation of float types −
print("\nThe string representation of float types...") for j in [np.float16, np.float32,np.float64]: print(np.sctype2char(j))
Example
import numpy as np # To return the string representation of a scalar dtype, use the sctype2char() method in Python Numpy # The 1st argument, 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. print("The string representation of a scalar type...") for i in [np.int32, np.double, np.complex_, np.string_, np.ndarray]: print(np.sctype2char(i)) # Return the string representation of int types print("\nThe string representation of int types...") for j in [np.int16, np.int32,np.int64]: print(np.sctype2char(j)) # Return the string representation of float types print("\nThe string representation of float types...") for j in [np.float16, np.float32,np.float64]: print(np.sctype2char(j))
Output
The string representation of a scalar type... i d D S O The string representation of int types... h i l The string representation of float types... e f d
Advertisements