「NumPy」np.iinfo関数にデータ型文字列を指定するサンプル

環境
Python3.9.2
PyCharm 2021.3.3

書式
class numpy.iinfo(type)
引数:int_typeinteger type, dtype, or instance
np.iinfo()を使って、整数int, uintや浮動小数点数floatの各データ型の範囲を取得します。
np.iinfo('文字列’)
引数にはデータ型dtypeを示す文字列('int16’、’i4’など)指定します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import numpy as np
print("データ型dtypeを文字列int16指定")
print(np.iinfo('int16'))
print("データ型dtypeを文字列uint64指定")
print(np.iinfo('uint64'))
print("データ型dtypeを文字列i4指定")
print(np.iinfo('i4'))
print(np.iinfo(int))
import numpy as np print("データ型dtypeを文字列int16指定") print(np.iinfo('int16')) print("データ型dtypeを文字列uint64指定") print(np.iinfo('uint64')) print("データ型dtypeを文字列i4指定") print(np.iinfo('i4')) print(np.iinfo(int))
import numpy as np

print("データ型dtypeを文字列int16指定")
print(np.iinfo('int16'))

print("データ型dtypeを文字列uint64指定")
print(np.iinfo('uint64'))

print("データ型dtypeを文字列i4指定")
print(np.iinfo('i4'))

print(np.iinfo(int))

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
データ型dtypeを文字列int16指定
Machine parameters for int16
---------------------------------------------------------------
min = -32768
max = 32767
---------------------------------------------------------------
データ型dtypeを文字列uint64指定
Machine parameters for uint64
---------------------------------------------------------------
min = 0
max = 18446744073709551615
---------------------------------------------------------------
データ型dtypeを文字列i4指定
Machine parameters for int32
---------------------------------------------------------------
min = -2147483648
max = 2147483647
---------------------------------------------------------------
Machine parameters for int32
---------------------------------------------------------------
min = -2147483648
max = 2147483647
---------------------------------------------------------------
データ型dtypeを文字列int16指定 Machine parameters for int16 --------------------------------------------------------------- min = -32768 max = 32767 --------------------------------------------------------------- データ型dtypeを文字列uint64指定 Machine parameters for uint64 --------------------------------------------------------------- min = 0 max = 18446744073709551615 --------------------------------------------------------------- データ型dtypeを文字列i4指定 Machine parameters for int32 --------------------------------------------------------------- min = -2147483648 max = 2147483647 --------------------------------------------------------------- Machine parameters for int32 --------------------------------------------------------------- min = -2147483648 max = 2147483647 ---------------------------------------------------------------
データ型dtypeを文字列int16指定
Machine parameters for int16
---------------------------------------------------------------
min = -32768
max = 32767
---------------------------------------------------------------

データ型dtypeを文字列uint64指定
Machine parameters for uint64
---------------------------------------------------------------
min = 0
max = 18446744073709551615
---------------------------------------------------------------

データ型dtypeを文字列i4指定
Machine parameters for int32
---------------------------------------------------------------
min = -2147483648
max = 2147483647
---------------------------------------------------------------

Machine parameters for int32
---------------------------------------------------------------
min = -2147483648
max = 2147483647
---------------------------------------------------------------

 

NumPy

Posted by arkgame