import numpy as np
A = np.array([[4, 4, 19, 19, 20, 21, 25, 26, 26, 27, 27, 29], [1, 2, 1, 2, 
    1, 2, 1, 1, 2, 1, 2, 2], [1, 1, 3, 3, 1, 2, 1, 1, 1, 2, 2, 2]])
values, inverse = np.unique(A[0], return_inverse=True)
B = np.zeros((3, len(values)))
B[0] = values
B[1, inverse[A[1] == 1]] = A[2, A[1] == 1]
B[2, inverse[A[1] == 2]] = A[2, A[1] == 2]
Преобразование значения в индекс строки в массиве NumPy