LoginSignup
0
1

More than 5 years have passed since last update.

Numpy > fileIO > 1次元のデータをファイルに追記する

Posted at
動作環境
GeForce GTX 1070 (8GB)
ASRock Z170M Pro4S [Intel Z170chipset]
Ubuntu 16.04 LTS desktop amd64
TensorFlow v1.2.1
cuDNN v5.1 for Linux
CUDA v8.0
Python 3.5.2
IPython 6.0.0 -- An enhanced Interactive Python.
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)
scipy v0.19.1
geopandas v0.3.0
MATLAB R2017b (Home Edition)
ADDA v.1.3b6
gnustep-gui-runtime v0.24.0-3.1

処理概要

1次元のデータをファイルに追記する。

取得したセンサーのデータをファイルに追記する処理などに使う。

Numpyでのファイル保存処理を使う。

code

test_logger_180304.py
import numpy as np

# on Python 3.5.2

OUTFILE = 'log.test_180304'

tpl = 3.14, 2.718, 6.022
tpl = [tpl]  # to avoid LF for 1-D array
with open(OUTFILE, 'ab') as f_hndl:
    for loop in range(5):
        np.savetxt(f_hndl, tpl, fmt='%.1f', delimiter=' ')

run
$ python3 test_logger_180304.py
$ cat log.test_180304 
3.1 2.7 6.0
3.1 2.7 6.0
3.1 2.7 6.0
3.1 2.7 6.0
3.1 2.7 6.0

関連

tpl = [tpl] # to avoid LF for 1-D array
がない場合、[3列]でなく[1列+改行]*3での出力になる。

0
1
0

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