9951 explained code solutions for 126 technologies


python-numpyInsert values into Numpy array at multiple positions


import numpy as np
a = np.array([5, 6, 6, 8, 9])

np.insert(a, [2, 4], 7)ctrl + c
import numpy as np

load Numpy module for Python

np.array

declare Numpy array

np.insert

insert specified value at specified position

[2, 4]

list of positions to insert given value at

7

value to insert