In my function, sometimes I get a result that is a 1 dimensional numpy array in 2D form, so that it's shape is nx1 (n,1). Other times, I might get it in the form 1xn array.shape = (1,n)
Other times, I get just a numpy array whose shape is (n,).
when I run the following tests, I get an error on the one hand, and a false positive on the other (since the length of a shape attribute is always greater than 1, apparently):
y_predicted = forest.predict(testX)
if y_predicted.shape[1] != None:
y_predicted = y_predicted.T[0]
and
y_predicted = forest.predict(testX)
if len(y_predicted.shape) > 1:
y_predicted = y_predicted.T[0]
I just need to make sure the final shape of y is always in the form (n,) rather than (n,1) or (1,n)...
squeeze,ravelandflattenwill all do this job; but read their docs so you understand their differences.