Pythonのインスタンスでfloatのマシン制限情報を取得する
floatタイプのマシン制限情報を取得するには、PythonNumpyのnumpy.finfo()メソッドを使用します。最初のパラメータはfloatです。つまり、情報を取得するためのfloatデータ型の種類です。
ステップ
まず、必要なライブラリをインポートします-
import numpy as np
minは指定されたdtypeの最小値であり、maxは指定されたdtypeの最小値です。
インスタンスを使用したfloat16タイプの確認-
a = np.finfo(np.float16(12.5))
print("Minimum of float16 type...\n",a.min)
print("Maximum of float16 type...\n",a.max) インスタンスを使用したfloat32タイプのチェック-
b = np.finfo(np.float32(30.5))
print("\nMinimum of float32 type...\n",b.min)
print("Maximum of float32 type...\n",b.max) インスタンスを使用したフロートタイプの確認-
c = np.finfo(np.float64(55.9))
print("\nMinimum of float64 type...\n",c.min)
print("Maximum of float64 type...\n",c.max) 例
import numpy as np
# To get the machine limits information for float types, use the numpy.finfo() method in Python Numpy
# The first parameter is the float i.e. the kind of float data type to get information about.
# Checking for float16 type with instances
# The min is the minimum value of given dtype.
# The max is the minimum value of given dtype.
a = np.finfo(np.float16(12.5))
print("Minimum of float16 type...\n",a.min)
print("Maximum of float16 type...\n",a.max)
# Checking for float32 type with instances
b = np.finfo(np.float32(30.5))
print("\nMinimum of float32 type...\n",b.min)
print("Maximum of float32 type...\n",b.max)
# Checking for float type with instances
c = np.finfo(np.float64(55.9))
print("\nMinimum of float64 type...\n",c.min)
print("Maximum of float64 type...\n",c.max) 出力
Minimum of float16 type... -65500.0 Maximum of float16 type... 65500.0 Minimum of float32 type... -3.4028235e+38 Maximum of float32 type... 3.4028235e+38 Minimum of float64 type... -1.7976931348623157e+308 Maximum of float64 type... 1.7976931348623157e+308
-
Python Pandas –データ型とDataFrame列の情報を取得します
データ型とDataFrame列の情報を取得するには、info()メソッドを使用します。必要なライブラリをエイリアスでインポートします- import pandas as pd; 3列のデータフレームを作成する- dataFrame = pd.DataFrame( { "Car": ['BMW', 'Audi', 'BMW', 'Lexus', 'Tesla', 'Lexus', 'Mustang'
-
Pythonで右寄せされた元の文字列でスペースが埋め込まれた文字列を取得するにはどうすればよいですか?
パディング後の文字列の合計の長さである「width」に等しい長さの文字列で右寄せされた文字列を返すメソッドrjust()を使用できます。パディングは、指定されたfillcharを使用して行われます(デフォルトはスペースです)。 widthがlen(s)未満の場合、元の文字列が返されます。例: >>> '15'.rjust(10) ' 15' >>> 'Yes'.rjust(2) 'Yes' >>> >>>