Here is a hacky way but slower compared to using np.transpose
. This is achieved by inserting 0
's in between the elements using slice
and then adding the lists together:
# e.g.
# arr1 = [1, 0, 0, 2, 0, 0, 3, 0, 0]
# arr2 = [0, 1, 0, 0, 2, 0, 0, 3, 0]
# arr3 = [0, 0, 1, 0, 0, 2, 0, 0, 3]
#
# arr_ = [1, 1, 1, 2, 2, 2, 3, 3, 3] # use np.add to fast insert
list1 = np.insert(list1, slice(1, None, 1), 0) # create 0,0 paddings in between
list1 = np.insert(list1, slice(1, None, 2), 0)
list1 = np.insert(list1, 0, [0]*(0))
list1 = list1.tolist()
list1.extend([0]*(3-1))
list2 = np.insert(list2, slice(1, None, 1), 0)
list2 = np.insert(list2, slice(1, None, 2), 0)
list2 = np.insert(list2, 0, [0]*(0+1))
list2 = list2.tolist()
list2.extend([0]*(3-2))
list3 = np.insert(list3, slice(1, None, 1), 0)
list3 = np.insert(list3, slice(1, None, 2), 0)
list3 = np.insert(list3, 0, [0]*(0+2))
list3 = list3.tolist()
list3.extend([0]*(3-3))
list_ = np.add(list1, list2)
list_ = np.add(list_, list3)
list_
array([ 1, 10, 20, 2, 11, 21, 3, 12, 22])