RabbitBadger
RabbitBadger

Reputation: 589

Losing 2nd dimension data of an array saved in .CSV and reloaded with numpy

I have a dataset with the following shape saved as a 3-dimensional array (7352, 128, 6)

I want to save my data as 6 different files based on the 3rd dimension of the array

The code I used is below:

np.savetxt(filepath+'/'+dataName1+'.csv', normalizedX[:,:,0], delimiter=',')
np.savetxt(filepath+'/'+dataName2+'.csv', normalizedX[:,:,1], delimiter=',')
np.savetxt(filepath+'/'+dataName3+'.csv', normalizedX[:,:,2], delimiter=',')
np.savetxt(filepath+'/'+dataName4+'.csv', normalizedX[:,:,3], delimiter=',')
np.savetxt(filepath+'/'+dataName5+'.csv', normalizedX[:,:,4], delimiter=',')
np.savetxt(filepath+'/'+dataName6+'.csv', normalizedX[:,:,5], delimiter=',')

The shape of normalizedX[:,:,0] is (7352, 128) before saving them.

When I try to load the text with the following code:

def load_file(filepath):
    dataframe = pd.read_csv(filepath, header=None, delim_whitespace=True)
    return dataframe.values

I get a shape of (7352, 1), I lost data from my 2nd dimension!

What is the problem here?

Upvotes: 0

Views: 45

Answers (1)

Omar Aldakar
Omar Aldakar

Reputation: 545

You used , as a delimiter in np.savetxt so you should not put delim_whitespace='True' in your read_csv function

Upvotes: 1

Related Questions