I have 2 arrays one is a Large_arr and another is (a subset of it) sub_arr. I want to map the values of both the array and the matched values of the array will return indices of the large array. I have my code but it throws an error
Traceback (most recent call last):
File "C:/Users/hp/AppData/Local/Programs/Python/Python36/stack.py", line 36, in <module>
if(sub_arr[i]==Large_arr[j]):
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
My code is
import numpy as np
Large_arr=np.array([[0.12046862, 0.64457892],
[0.47522597, 0.12350968],
[0.1649585 , 0.50135502],
[0.20104755 ,0.15218623],
[0.03772419 ,0.42482297],
[0.51633778 ,0.61209002],
[0.24848648 ,0.99651906],
[0.47374345, 0.09990318],
[0.58390815 ,0.19781604],
[0.9613725 ,0.45975827],
[0.99008266 ,0.13487207],
[0.14410988 ,0.36196475],
[0.81349573 ,0.55896232],
[0.72841399 ,0.02263056],
[0.8692731 ,0.9754183 ],
[0.87142787 ,0.66163271],
[0.24342035 ,0.95821073],
[0.94218857 ,0.7220602 ],
[0.66716105 ,0.96875209]])
sub_arr=np.array([[0.12046862, 0.64457892],
[0.51633778 ,0.61209002],
[0.99008266 ,0.13487207],
[0.72841399 ,0.02263056],
[0.24342035 ,0.95821073],
[0.47374345, 0.09990318],
[0.9613725 ,0.45975827]])
s=[]
for i in range(0,len(Large_arr)):
for j in range(0,len(sub_arr)):
if(sub_arr[i]==Large_arr[j]):
s.append(j)
print("Value of s is\n",s)
else:
print("Value is none\n")
Can this method be simplifed. So my output has value
S=[0,5,10,13,7,10,1] (example, index of large array where sub_array value stored)