79487343

Date: 2025-03-05 18:18:47
Score: 1
Natty:
Report link

How about something like this?

keys = np.union1d(a[:, 0], b[:, 0])

# Initialize result array with zeros - assume the 3 columns as output
c = np.zeros((keys.shape[0], 3))
c[:, 0] = keys

idx_a = np.searchsorted(keys, a[:, 0])
idx_b = np.searchsorted(keys, b[:, 0])

# Assign values where keys match
c[idx_a, 1] = a[:, 1]
c[idx_b, 2] = b[:, 1]

print(c)

"""
[[1.  0.2 0. ]
 [2.  0.5 0.4]
 [3.  0.8 0.7]
 [4.  0.  1.3]
 [5.  0.  2. ]]
"""
Reasons:
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Starts with a question (0.5): How
  • High reputation (-1):
Posted by: Chrispresso