Tom
Tom

Reputation: 289

Numpy Arrays, wrong shape

I'm taking an entry level ML course and I'm working on analysing the iris dataset from the sklearn library, and one thing I need to do is print out the third feature associated with the list of data. I also need to make sure that the shape is (150,).

What I tried:

x = iris.data[:, 2:3] Which does give me the third feature, but the shape is (150,1) rather than (150,) and I don't quite understand why.

Would appreciate some help, thanks in advance.

Upvotes: 0

Views: 297

Answers (1)

Julien
Julien

Reputation: 15071

iris.data[:, 2:3] gives you a view of features 2 (incl) to 3 (excl), think of that as a list of 1 feature, hence the last 1 in your shape. Just use iris.data[:, 2] directly to make it a 1 dimensional array (whose shape has length 1).

Upvotes: 1

Related Questions