NoSuchUserException
NoSuchUserException

Reputation: 730

boolean array not replicating itself for other dimensions numpy

I have two arrays y dims (1x100) and X dims (3x100)

I want to select all those values from X where y is 0 and all values where y is 1.

I have tried doing X[y==0] to get all those values where y is 0 but it doesn't work for dim 0 of X which is 3.

Any suggestions on how to do it?

Thanks

Upvotes: 0

Views: 30

Answers (1)

piRSquared
piRSquared

Reputation: 294488

You need to align dimensions correctly

X[:, y[0] == 0]

The first : specifies to grab everything in the first dimension. Using the y[0] == 0 in the second slot specifies that we are indexing the second dimension.

Upvotes: 1

Related Questions