返回 Python 中資料型別程式碼的描述
要返回給定資料型別程式碼的描述,請使用 Python Numpy 中的 typeName() 方法。NumPy 提供了全面的數學函式、隨機數生成器、線性代數例程、傅立葉變換等等。它支援廣泛的硬體和計算平臺,並與分散式、GPU 和稀疏陣列庫配合使用。
步驟
首先,匯入所需的庫 -
import numpy as np
我們的陣列 -
arr = ['S1', '?', 'B', 'D', 'G', 'F', 'I', 'H', 'L', 'O', 'Q', 'S', 'U', 'V', 'b', 'd', 'g', 'f', 'i', 'h', 'l', 'q']
要返回給定資料型別程式碼的描述,請使用 Python Numpy 中的 typeName() 方法,第 1 個引數是日期型別程式碼 -
for i in arr: print(i, ' : ', np.typename(i))
示例
import numpy as np # declaring arr = ['S1', '?', 'B', 'D', 'G', 'F', 'I', 'H', 'L', 'O', 'Q', 'S', 'U', 'V', 'b', 'd', 'g', 'f', 'i', 'h', 'l', 'q'] # To return a description for the given data type code, use the typename() method in Python Numpy # The 1st argument is the Data type code for i in arr: print(i, ' : ', np.typename(i))
輸出
S1 : character ? : bool B : unsigned char D : complex double precision G : complex long double precision F : complex single precision I : unsigned integer H : unsigned short L : unsigned long integer O : object Q : unsigned long long integer S : string U : unicode V : void b : signed char d : double precision g : long precision f : single precision i : integer h : short l : long integer q : long long integer
廣告。