Jose Ramon
Jose Ramon

Reputation: 5442

Convert numpy array shape from (1, 100 ) to (100, ) in python

I have a np.array that I want to store it in a mat file and then to load it from my code. The code for storing it to mat file is the following:

data = {'reduced_train_face': reduced_train_face.tolist(),
        'reduced_train_audio': reduced_train_audio.tolist(),
        'reduced_audio_labels': reduced_audio_labels.tolist()}

m4p.savemat('data.mat', data)

And then the code for retrieving the info is the following:

reduced_audio_labels = np.array(data['reduced_audio_labels'])

I have noticed that the type of file is changing. The file before the loading was of type:

enter image description here

and when I loaded the file:

enter image description here

That change cause me several issues. How can I convert : (1, 100 ) to : (100, )??

Upvotes: 1

Views: 4798

Answers (1)

Nils Werner
Nils Werner

Reputation: 36765

np.squeeze(reduced_audio_labels)

will remove superfluous dimensions

Upvotes: 2

Related Questions