Python: Check if a numpy array contains an object with specific attribute
<p>I want to check if there is any object with a specific attribute in my numpy array:</p>

<pre><code>class Test:
def __init__(self, name):
    self.name = name

l = numpy.empty( (2,2), dtype=object)
l[0][0] = Test("A")
l[0][1] = Test("B")
l[1][0] = Test("C")
l[1][1] = Test("D")
</code></pre>

<p>I know that following line of code working for a list, but what is the alternative process for a numpy array?</p>

<pre><code>print numpy.any(l[:,0].name == "A")
</code></pre>

<p>I'm clearly not proficient in numpy but couldn't you just do something like:</p>

<pre><code>numpy.any([ x.name=='A' for x in l[:,0] ])
</code></pre>

<p>edit:
(Google tells me that) it's possible to iterate over arrays with <code>nditer</code>; is this what you want?</p>

<pre><code>numpy.any([ x.name=='A' for x in numpy.nditer(l) ])
</code></pre>

python python-2.7 numpy