hugo
hugo

Reputation: 21

boolean index did not match indexed array along dimension

This code is in my book

rlr.get_support()
print(u'有效特征为:%s' % ','.join(data.columns[rlr.get_support()]))

I got the error

IndexError: boolean index did not match indexed array along dimension 0;dimension is 9 but corresponding boolean dimension is 8
the rlr.get_support() index is 8 and data.colunms is 9

is this because my python is python 3.5?

Upvotes: 1

Views: 19137

Answers (2)

HeCCXX
HeCCXX

Reputation: 21

you can use the following code:

r1.get_support(indices=True)
print(u'有效特征为:%s' % ','.join(data.columns[rlr.get_support()]))

I think the reason for the Indexerror is the version of numpy.you can look at the docs。 [https://docs.scipy.org/doc/numpy-1.13.0/user/basics.indexing.html#index-arrays][1]

Boolean arrays must be of the same shape as the initial dimensions of the array being indexed.

Upvotes: 2

remram
remram

Reputation: 5203

No, it is not because of the Python version. It is because data.columns[...] expects an array of the same size, that is used as a mask (True values in the mask will include that element from data.columns, False values will skip it).

It is impossible to give more details with the amount of information you have provided.

Upvotes: 2

Related Questions