numpy - return index If value inside one of 3d array
<p>How to do this in Numpy : Thank you!</p>

<p><strong>Input :</strong> </p>

<pre><code>A = np.array([0, 1, 2, 3]) 

B = np.array([[3, 2, 0], [0, 2, 1], [2, 3, 1], [3, 0, 1]]) 
</code></pre>

<hr>

<p><strong>Output :</strong></p>

<pre><code>result = [[0, 1, 3], [1, 2, 3], [0, 1, 2], [0, 2, 3]]
</code></pre>

<hr>

<p>in Python :</p>

<pre><code>A = np.array([0 ,1 ,2 ,3]) 
B = np.array([[3 ,2 ,0], [0 ,2 ,1], [2 ,3 ,1], [3 ,0 ,1]]) 
result = []
for x ,  valA in enumerate (A) :
    inArray = []
    for y , valB in enumerate (B) : 
        if valA in valB:
            inArray.append (y)
    result.append (inArray)
print result

# result = [[0, 1, 3], [1, 2, 3], [0, 1, 2], [0, 2, 3]]
</code></pre>

<p>An option with a combination of <code>numpy</code> and <code>list-comprehension</code>:</p>

<pre><code>import numpy as np
[np.where((B == x).sum(axis = 1))[0] for x in A]
# [array([0, 1, 3]), array([1, 2, 3]), array([0, 1, 2]), array([0, 2, 3])]
</code></pre>

python arrays numpy indexing collect