LoginSignup
0
1

More than 5 years have passed since last update.

Python > tuple > (3., 1., 4.)を 3.00000,1.00000,4.00000にする (小数点を5桁に) > .join使用

Last updated at Posted at 2017-03-24
動作環境
Xeon E5-2620 v4 (8コア) x 2
32GB RAM
CentOS 6.8 (64bit)
openmpi-1.8.x86_64 とその-devel
mpich.x86_64 3.1-5.el6とその-devel
gcc version 4.4.7 (とgfortran)
NCAR Command Language Version 6.3.0
WRF v3.7.1を使用。
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37) 
Python 3.6.0 on virtualenv

タイトルのことをしようとしている。

http://qiita.com/7of9/items/4aa9f546a4ff1bf2e1aa
のコメントにて色々方法を教えていただいた。

別途、以下を見つけた。
http://stackoverflow.com/questions/15968017/formatting-a-tuple-of-floats

こちらを実装してみた。

test_python_170324b.py
import numpy as np

atuple = (3., 1., 4., 1., 5., 9., 2., 6., 5., 3., 5.)

astr=','.join(format(elem, '.5f') for elem in atuple)
print(astr)
結果
$ python test_python_170324b.py 
3.00000,1.00000,4.00000,1.00000,5.00000,9.00000,2.00000,6.00000,5.00000,3.00000,5.00000

色々やり方はありそうで、自分が「そらで」使えるようになるもの(かつ可読性が高いもの)は検討中。

教えていただいた事項

(追記 2017/03/24)

@shiracamus さんのコメントの書き方の方が簡潔で読みやすいように思います。

情報感謝です。

0
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1