스칼라 dtype의 문자열 표현을 반환하려면 PythonNumpy에서 sctype2char() 메서드를 사용합니다. 첫 번째 인수는 스칼라 dtype인 경우 해당 문자열 문자가 반환됩니다. 객체인 경우 sctype2char는 해당 스칼라 유형을 추론한 다음 해당 문자열 문자를 반환합니다.
단계
먼저 필요한 라이브러리를 가져옵니다 -
import numpy as np
스칼라 유형의 문자열 표현 -
for i in [np.int32, np.double, np.complex_, np.string_, np.ndarray]: print(np.sctype2char(i))
int 유형의 문자열 표현 반환 -
print("\nThe string representation of int types...")
for j in [np.int16, np.int32,np.int64]:
print(np.sctype2char(j)) float 유형의 문자열 표현 반환 -
print("\nThe string representation of float types...")
for j in [np.float16, np.float32,np.float64]:
print(np.sctype2char(j)) 예시
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)) 출력
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