Python: separate matrix by column values
Question: I have a matrix `A` with 3 columns that looks something like, but much larger:

    
    
    [[10 15 1.0]
     [21 13 1.0]
     [9  14 0.0]
     [14 24 1.0]
     [21 31 0.0]
     ...]
    

I want to create two separate matrices: one that contains all of the data with
the third column=0.0, and another with all the data with the third column=1.0.
So essentially splitting the data by the values 0.0 or 1.0 in the third
column.


Answer: If you're using [Numpy](http://docs.scipy.org/doc/numpy/reference/), first
find the rows where the third column has your desired value, then extract the
rows using
[indexing](http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html).

**Demo**

    
    
    >>> import numpy
    >>> A = numpy.array([[1, 0, 1],
                         [2, 0, 1],
                         [3, 0, 0],
                         [4, 0, 0],
                         [5, 0, 0]])
    >>> A1 = A[A[:, 2] == 1, :] # extract all rows with the third column 1
    >>> A0 = A[A[:, 2] == 0, :] # extract all rows with the third column 0
    >>> A0
    array([[3, 0, 0],
           [4, 0, 0],
           [5, 0, 0]])
    >>> A1
    array([[1, 0, 1],
           [2, 0, 1]])
    

