##やりたいこと
ndarrayの数値で2.080000000000000000e+02を2.08e+02のように丸めたいです。
これをnumpyかpythonで行いたいと考えています。
#試したこと
以下のコマンドで試しましたが、上手く動きませんでした。
python
1np.array2string(image, formatter={'float_kind':lambda x: "%.2f" % image}) 2np.set_printoptions(precision=3) 3np.set_printoptions(formatter={'float':'{:.2e}'.format})
python
1from PIL import Image 2import numpy as np 3 4image = np.array(Image.open('./Desktop/dog.jpg').convert('L')) 5np.set_printoptions(formatter={'float':'{:.2e}'.format}) 6 7print(image.shape, image.dtype) 8 9print(image) 10 11np.savetxt('./Desktop/image_ndarray.txt', image)
2.080000000000000000e+02 2.070000000000000000e+02 2.060000000000000000e+02 2.050000000000000000e+02 2.040000000000000000e+02 2.030000000000000000e+02 2.030000000000000000e+02 2.030000000000000000e+02 1.990000000000000000e+02 1.980000000000000000e+02 1.980000000000000000e+02 1.980000000000000000e+02 1.980000000000000000e+02 1.980000000000000000e+02 1.980000000000000000e+02 1.980000000000000000e+02
#環境
python 3.6.7
numpy 1.15.4
Linux
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/12/25 13:17 編集
2018/12/25 13:16
2018/12/25 13:36
2018/12/25 13:43