Reputation: 437
I'm using np.argmax function in one of my python programme for one of my data frame which is completely sparse matrix.my data frame contains 253 rows & 22 column. The head function return this sample data set
var1 var2 Var3 var4 ... .. var18 var19 ... var22
0 0 0 0 ...... 0 1 ... 0
0 0 0 0 ...... 0 0 ... 1
0 0 1 0 ...... 0 0 ... 0
0 0 0 1 ...... 0 0 ... 0
0 0 0 0 ...... 1 0 ... 0
I'm using following code
y=np.argmax(train_y, axis=1)
While running this code I'm getting error message
ValueError: Shape of passed values is (1, 253), indices imply (22, 253)
Can you expert please help me to solve this problem?
Thanks in advance
Upvotes: 0
Views: 814
Reputation: 7977
The code works fine for me when I use -
y=np.argmax(train_y.values, axis=1)
The np.argmax
is a numpy function, passing in a dataframe could be causing this error. Instead convert it into a numpy nd array using the .values
attribute of dataframes
Upvotes: 1