0
arr_1 = np.array([5, 1, 6, 3, 3, 10, 3, 6, 12])
arr_2 = np.array([10, 20, 30, 40, 50, 60, 70, 80, 90])
arr_idx_num_3 = np.where(arr_1 == 3)[0]
print(arr_idx_num_3)  ## [3 4 6]

#how to i get this array Numpy with "arr_idx_num_3"

arr_2 = [40 50 70]
1
  • arr_2[arr_1 == 3] also works if both arrays are guaranteed to be the same size. Commented Jan 23, 2022 at 16:42

4 Answers 4

1

Just use it like:

print(arr_2[arr_idx_num_3])

output:

>>> [40 50 70]
Sign up to request clarification or add additional context in comments.

Comments

0

A simple for loop should do the trick.

import numpy as np

arr_1 = np.array([5, 1, 6, 3, 3, 10, 3, 6, 12])
arr_2 = np.array([10, 20, 30, 40, 50, 60, 70, 80, 90])


idx_num = 3
arr_idx_num = []
for i in range(len(arr_1)):
    if arr_1[i] == idx_num:
        arr_idx_num.append(arr_2[i])

Comments

0

One way is:

indices = [i for i, x in enumerate(arr_1) if x == 3]
arr_2[indices]

Comments

0
import numpy as np
  
arr_1 = np.array([5, 1, 6, 3, 3, 10, 3, 6, 12])
arr_2 = np.array([10, 20, 30, 40, 50, 60, 70, 80, 90])

arr_idx_num_3 = np.nonzero(arr_1==3)
print(arr_2[arr_idx_num_3])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.