0

I have 2 arrays where I would like to compare the index number not the element against another array's elements that would correspond to that index number and return the element.

array 1
index 0 = [cat]
index 1 = [dog]
index 2 = [bird]
index 3 = [mouse]

array 2
 [2]
 [1]
 [0]
 [3]
expected result:

[bird]
[dog]
[cat]
[mouse]

Expected results: array 1:index 0 = cat ,index 1 = dog,index 2 = bird,index 3 = mouse

array 2: 2, 1, 0, 3

expected result: bird,dog,cat,mouse

user11861166
  • 159
  • 7
  • 1
    You should consider editing your question so your code examples are valid python: `list1 = ['cat', 'dog']` `list2 = [2, 1, 0, 3]` etc. It makes it much easier to understand your questions and easier to help you. – Mark Aug 01 '19 at 00:01
  • I fear this may be an "XY" problem. Can you maybe tell us what problem you are trying to solve? I suspect that what you actually want to do is put 'cat' 'dog' etc into a dictionary, but it really depends on the context here. – sgillen Aug 01 '19 at 00:08
  • If you're using NumPy, just do `array1[array2]`. – iz_ Aug 01 '19 at 00:15
  • This is part of a larger question in my programming assignment. I have 2 (75,5) arrays that are set up the same 4 columns of floats and the last column is string of names. I am limited to only a numpy import so I broke the arrays into 2 (75,4) and 2 (75,1) arrays. I am not essentially taking larger array index(not the element) to see where it is in the (75,1) as the indices will be out of order due functions being ran. – user11861166 Aug 01 '19 at 00:21

0 Answers0