pythonを使用して、指定のテキストファイルからデータを読み込み、ソースコード中の計算式で計算した結果を出力しようとしています。
現在、出力という行為自体はうまくいっておりテキストファイル、またpython shellへの出力は出来ているのですが…。
行列として出力を行うと以下のような結果になってしまいます。
[1 2 3 4 5 6
7 8 9 10 11 12
13 14 ...]
[1a 2a 3a 4a 5a 6a
7a 8a 9a 10a 11a 12a
13a 14a...]
上記の様に6列複数行の形で出力されてしまいます()。
データ量が膨大なため、何十列となるのは分かっていますがこれを1行ずつの行列に変換できないでしょうか?
理想としては上記の出力結果を
[1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...]
[1a 2a 3a 4a 5a 6a 7a 8a 9a 10a 11a 12a 13a 14a ...]
のように出来ればと考えております。
質問内容が分かりにくければコメントでご指摘お願い致します。
宜しくお願いします。
以下、使用しているソースコードになります(3次元グラフも出力しますが、ソースコードは省いてあります)。
python
1from mpl_toolkits.mplot3d import Axes3D 2import matplotlib.pyplot as plt 3from matplotlib import cm 4from matplotlib.ticker import LinearLocator, FormatStrFormatter 5import math 6import numpy as np 7 8np.set_printoptions(threshold=np.inf) 9 10def MaxMinNormalization(x): 11 x = (x - np.min(x)) / (np.max(x) - np.min(x)); 12 return x 13 14def morlet(t): 15 f0=0.849 16 jisuans=np.power(np.pi,-1/4)*(np.cos(-2*np.pi*f0*t)-np.exp(-np.power(2*np.pi*f0,2)/2))*np.exp(-np.power(t,2)/2) 17 qyosuans=np.power(np.pi,-1/4)*np.sin(-2*np.pi*f0*t)*np.exp(-np.power(t,2)/2) 18 return jisuans,qyosuans 19 20f0=0.849 21 22#解析したいデータの読み込み 23x = np.arange(0.00,1.00,0.001) 24y = open("EMGwave_test.txt") 25 26lines1 = y.read() 27y.close() 28 29lines2 = lines1.split("\n") 30data=[] 31for line in lines2: 32 data.append(float(line)) 33y=data[0:1000] 34 35#Wavelet 36Hz=np.arange(50,100,1) 37aa=f0/Hz 38summ=[] 39for a in aa: 40 wbltb=[] 41 for b in x: 42 t=(x-b)/a 43 wblt1=1/math.sqrt(a)*sum(morlet(t)[0]*y) 44 wblt2=1/math.sqrt(a)*sum(morlet(t)[1]*y) 45 wblt=np.sqrt(wblt1*wblt1+wblt2*wblt2) 46 wbltb.append(wblt) 47 summ.append(wbltb) 48summ=np.array(summ) 49 50 51file = open("writing.txt","w") 52file.write(str(summ)) 53file.close() 54
回答1件
あなたの回答
tips
プレビュー