This is for machine learning. I have 5 matlab files: AWA, REM, S1, S2, SWS.
Each one has 2 arrays: x
and y
. y
are the labels. I want to know the number of instances for each category in each file:
I load the matlab file
I convert from
f8
toint32
If I do not use
ravel
,bincount
will not workI count the instances for each category in the file
I repeat these 4 steps 5 times (as there are 5 files). Is there a way to do it better?
Then I just join all the vectors in one array to send them to PANDAS.
#AWA
awa_y=sio.loadmat('/home/AWA_FeaturesAll.mat')['y']
awa_y=awa_y.astype('int') #from f8 to int32
awa=np.ravel(awa_y) #needed in order to use np.bincount()
AWA=np.bincount(awa)
#Rem
rem_y=sio.loadmat('/home/Rem_FeaturesAll.mat')['y']
rem_y=rem_y.astype('int')
rem=np.ravel(rem_y)
REM=np.bincount(rem)
#S1
s1_y=sio.loadmat('/home/S1_FeaturesAll.mat')['y']
s1_y=s1_y.astype('int')
s1=np.ravel(s1_y)
S1=np.bincount(s1)
#S2
s2_y=sio.loadmat('/home/S2_FeaturesAll.mat')['y']
s2_y=s2_y.astype('int')
s2=np.ravel(s2_y)
S2=np.bincount(s2)
#SWS
sws_y=sio.loadmat('/home/SWS_FeaturesAll.mat')['y']
sws_y=sws_y.astype('int')
sws=np.ravel(sws_y)
SWS=np.bincount(sws)
#Joining the 5 vectors
table= (np.vstack((AWA, REM, S1, S2, SWS))).T
TABLE = np.delete(table, (0), axis=0)
print(TABLE)
sio
appears to bescipy.io
. \$\endgroup\$