Operating environment
GeForce GTX 1070 (8GB)
ASRock Z170M Pro4S [Intel Z170chipset]
Ubuntu 14.04 LTS desktop amd64
TensorFlow v0.11
cuDNN v5.1 for Linux
CUDA v8.0
Python 2.7.6
IPython 5.1.0 -- An enhanced Interactive Python.
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
GNU bash, version 4.3.8(1)-release (x86_64-pc-linux-gnu)
Run in Python2 environment.
input.tab
Tab-delimited files.
x y z E v1 v2
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
result.csv
3, 1, 4, 1, 5
3, 1, 4, 1, 5
3, 1, 4, 1, 5
It is assumed that the values of x, y, z, v1, v2 are stored.
output.tab
I want to create the following file.
x y z E v1 v2
3.000 1.000 4.000 4.000 1.000 5.000
3.000 1.000 4.000 4.000 1.000 5.000
3.000 1.000 4.000 4.000 1.000 5.000
--I want to replace values other than E with the values in result.csv --Any number of decimal places
code v0.1
*
Used in Python3 cannot be used in Python2.
I tried various things and ended up with the following solid writing.
merge_170503.py
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
tabdat = np.genfromtxt('input.tab', delimiter=' ')
csvdat = np.genfromtxt('result.csv', delimiter=',')
for aline in zip(tabdat[1:], csvdat): # 1:skip title line
for idx in range(0, 3):
print("%.3f" % aline[1][idx], end=' ')
print("%.3f" % aline[0][3], end=' ')
for idx in range(3, 5):
print("%.3f" % aline[1][idx], end=' ')
print()
$ python merge_170503.py
3.000 1.000 4.000 4.000 1.000 5.000
3.000 1.000 4.000 4.000 1.000 5.000
3.000 1.000 4.000 4.000 1.000 5.000
When I try to run it in Python3, I get the following problem. We have to think about improving the environment.
No module named numpy
@ shiracamus's Comment introduced a clean code using numpy.c_
.
Thank you for the information. https://docs.scipy.org/doc/numpy/reference/generated/numpy.c_.html
A search on numpy.c_ also found an article on Qiita. Concatenate matrices with Numpy NumPy array operation (2)
Recommended Posts