我從文件中加載一些數據,進行轉換,然後提取實數部分,但是,np.real函數似乎不起作用。它打印:在python中提取數組的實數部分
[[(0.99023793104890667 + 0.034016079376604003j)0.9905214315431583 0.99033818364852688 ...,0.86609847609098078 0.87048246890045189無]]
其中清楚地,第一元件是複雜的。
import numpy as np
import scipy.io as sio
import os.path
import PLVHilbertImplementation as pet
import matplotlib.pyplot as plt
import Likelihood_gen as lg
#for the interictal files
for j in range(1, 2, 1):
filename = '/home/kam/Documents/kaggle/Dog_5/Dog_5_interictal_segment_' + str(j).zfill(4) + '.mat'
PLVs=[]
if os.path.isfile(filename):
#For the files that exist do this
data=sio.loadmat(filename)['interictal_segment_1'][0][0][0][1:1024]
numchannels, numpoints = data.shape
label=np.ones((1,numpoints))
for i in range(0, 2, 1):
for j in range(i+1, 2, 1):
PLVs.append(np.asarray((pet.PLV(data[i,:],np.transpose(data[j,:]), 1024, 5, 128))))
print(np.real(PLVs)) #this is where the problem is
# Metric=np.sum(np.exp(np.real(np.asarray(PLVs)),1))
# plt.plot(Metric)
# plt.show
else:
print('no', filename)
break
#for the preictal files
for j in range(1, 1, 1):
filename = 'Dog_1_preictal_segment_' + str(j).zfill(4) + '.mat'
if os.path.isfile(filename):
data=sio.loadmat(filename)[0][0][0]
numchannels, numpoints = shape(data)
print(numchannels)
else:
print('no', filename)
break
謝謝galaxyan,但也不能正常工作。 –
@KamyarGhofrani在您轉換爲真實數據之前什麼是數據? – galaxyan
我正在讀取一個.mat文件,它會返回一個字典。然後我讀取字典中的值並將它們放入列表中。然後我使用np.asarray將列表轉換爲np數組。 –