I am looking for a fast method to merge two numpy arrays in python in the following fashion. For example, if I have the following two arrays,
arr1 = np.array([0.0, 1.0, 11.0, 111.0])
arr2 = np.array([0.5, 1.5, 11.5, 111.5])
then I would want the merged array (say arr3
) to contain elements of arr1
and arr2
in alternating indices. Like,
arr3 = np.array([0.0, 0.5, 1.0, 1.5, 11.0, 11.5, 111.0, 111.5])
I realize that I can achieve this using two for loops, where I can store elements of arr1
and arr2
into alternate indices (of arr3
). But, in my actual work, I will be dealing with huge arrays (arr1
and arr2
), and I want to make sure that I am using an efficient and fast approach to achieve this functionality (i.e. creation of arr3
)
I will very much appreciate any help.