0

If I have a numpy array

a = np.repeat([i for i in range(10)], 1000)

and another numpy array

b = np.arange(10, 20)

How do I insert the values of b into a based on index? So that all 0 = 10, 1 = 11 and so on. Is there something similar to matlab where you can say b(a)

2
  • 2
    Isn't it just b[a] ? Commented Apr 28, 2022 at 13:16
  • Sorry. My bad, you are right Commented Apr 28, 2022 at 13:20

1 Answer 1

1

Hope this helps you,

import numpy as np
a = np.repeat([i for i in range(10)], 1000)
b = np.arange(10, 20)
a=b[a]
print(a)

The output:
[10 10 10 ... 19 19 19]

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.