#PythonNumPyShapeIssue
Explore tagged Tumblr posts
softwarekar · 7 years ago
Text
Python numpyArray shape issue
Error:- ValueError: Found input variables with inconsistent numbers of samples: [150, 1] 
Solution: use numpy reshape method. 
 You are getting that error because your X and Y don't have the same length (which is what train_test_split requires), it means that ., X.shape[0] != Y.shape[0]. 
see below code:
 >>> X.shape (1, 5, 20)
 >>> Y.shape (20,) 
To fix this error: Remove the extra list from inside of np.array() when defining X or remove the extra dimension afterwards with the following command: 
 X = X.reshape(X.shape[1:]). 
 Now, the shape of X will be (5, 20). 
Transpose X by doing X = X.tranpose() to get equal number of samples in X and Y. 
 Now, the shape of X will be (20, 6) and the shape of Y will be (20,).
0 notes