Understanding numpy condition on array
<p>I don't understand some code from Kaggle's solution.  </p>

<p>Here is an example of the data: </p>

<pre><code>PassengerId,Survived,Pclass,Name,Sex,Age,SibSp,Parch,Ticket,Fare,Cabin,Embarked
1,0,3,"Braund, Mr. Owen Harris",male,22,1,0,A/5 21171,7.25,,S
2,1,1,"Cumings, Mrs. John Bradley (Florence Briggs Thayer)",female,38,1,0,PC 17599,71.2833,C85,C
3,1,3,"Heikkinen, Miss. Laina",female,26,0,0,STON/O2. 3101282,7.925,,S
</code></pre>

<p>The goal is to extract an array with only the female, and they do it like this: </p>

<pre><code># data contains all the passengers
women_only_stats = data[0::,4] == "female"
females_data = data[women]
print(data[women][0]) # Will print the first women of the dataset of only women. 
</code></pre>

<p>I understand that <code>women_data_only</code> will be an array of <code>True</code> and <code>False</code> which is the result of the evaluation of the expression <code>data[0::,4] == "female"</code>. <br> 
What I do not understand is why data[women] is an array of only women? <br>
<br> <br>How is <code>numpy</code> evaluate that?</p>

<p>Here's how it works:</p>

<p><code>women_only_stats = data[0::,4] == "female"</code> will create a <strong>mask</strong> (array of <code>booleans</code>) for the indices of your dataframe.</p>

<p>When passed to <code>data</code>, the mask will do a <strong>projection</strong> on the samples where  <code>women_only_stats</code> is <code>True</code>, thus keeping only women.</p>

<p>You can have a look <a href="http://docs.scipy.org/doc/numpy/user/basics.indexing.html#boolean-or-mask-index-arrays" rel="nofollow">here</a> about mask indexing.</p>

python arrays numpy