numpy mask for 2d array with all values in 1d array
<p>I want to convert a 2d matrix of dates to boolean matrix based on dates in a 1d matrix. i.e., </p>

<pre><code>[[20030102, 20030102, 20070102],
 [20040102, 20040102, 20040102].,
 [20050102, 20050102, 20050102]] 
</code></pre>

<p>should become</p>

<pre><code>[[True, True, False],
 [False, False, False].,
 [True, True, True]] 
</code></pre>

<p>if I provide a 1d array [20010203, <strong>20030102</strong>, 20030501, <strong>20050102</strong>, 20060101]</p>

<pre><code>import numpy as np

dateValues = np.array(
    [[20030102, 20030102, 20030102],
     [20040102, 20040102, 20040102],
     [20050102, 20050102, 20050102]])

requestedDates = [20010203, 20030102, 20030501, 20050102, 20060101]

ix = np.in1d(dateValues.ravel(), requestedDates).reshape(dateValues.shape)

print(ix)
</code></pre>

<p><strong>Returns:</strong></p>

<pre><code>[[ True  True  True]
 [False False False]
 [ True  True  True]]
</code></pre>

<p>Refer to <code>numpy.in1d</code> for more information (documentation):
<a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.in1d.html" rel="nofollow">http://docs.scipy.org/doc/numpy/reference/generated/numpy.in1d.html</a></p>

python numpy