[Numpy-discussion] How to subset a matrix according to some criterion?

2017-12-03 Thread Peng Yu
Hi, I'd like to select the rows of 'data' for which the corresponding
elements in 'target' is not 2. Could anybody let know what is the best
way (with the least code) to do conditional subsetting like this with
numpy objects? Thanks.

from sklearn import datasets
data, target = datasets.load_iris()

-- 
Regards,
Peng
___
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] How to subset a matrix according to some criterion?

2017-12-03 Thread Juan Nunez-Iglesias
selector = target != 2
data, target = data[selector], target[selector]

On 4 Dec 2017, 8:38 AM +1100, Peng Yu , wrote:
> Hi, I'd like to select the rows of 'data' for which the corresponding
> elements in 'target' is not 2. Could anybody let know what is the best
> way (with the least code) to do conditional subsetting like this with
> numpy objects? Thanks.
>
> from sklearn import datasets
> data, target = datasets.load_iris()
>
> --
> Regards,
> Peng
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
___
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion