how to mask the specific array data based on the shapefile
<h3>Here is my question:</h3>

<ul>
<li>the 2-d numpy array data represent some property of each grid space</li>
<li>the shapefile as the administrative division of the study area(like a city).      </li>
</ul>

<h3>For example:</h3>

<p><a href="http://i4.tietuku.com/84ea2afa5841517a.png" rel="nofollow noreferrer">http://i4.tietuku.com/84ea2afa5841517a.png</a></p>

<p>The whole area has 40x40 grids network, and I want to extract the data inside the purple area. In other words , I want to mask the data outside the  administrative
boundary into np.nan.     </p>

<h3>My early attempt</h3>

<p>I label the grid number and select the specific array data into np.nan.     </p>

<p><a href="http://i4.tietuku.com/523df4783bea00e2.png" rel="nofollow noreferrer">http://i4.tietuku.com/523df4783bea00e2.png</a>   </p>

<pre><code> value[0,:] = np.nan
 value[1,:] = np.nan
       .
       . 
       .
       .
</code></pre>

<p>Can Someone show me a easier method to achieve the target? </p>

<h3>Add</h3>

<p>Found an answer <a href="http://basemaptutorial.readthedocs.org/en/latest/clip.html" rel="nofollow noreferrer">here</a>    which can plot the raster data into shapefile, but the data itself doesn't change.    </p>

<h3>Update -2016-01-16</h3>

<p>I have already solved this problem inspired by some answers.<br>
Someone which are interested on this target, check this two posts which I have asked:<br>
1. <a href="https://stackoverflow.com/questions/34825074/testing-point-with-in-out-of-a-vector-shapefile">Testing point with in/out of a vector shapefile</a><br>
2. <a href="https://stackoverflow.com/questions/25701321/how-to-use-set-clipped-path-for-basemap-polygon/34224925#34224925">How to use set clipped path for Basemap polygon</a>    </p>

<p>The key step was to test the point within/out of the shapefile which I have already transform into shapely.polygon.    </p>