0

At the current moment, I am trying to combine an array of titles with a corresponding ID number (in String format) into a larger array as such:

import numpy as np
titles = np.array(['title1', 'title2', 'title3'])
IDs = np.array(['1543', '1231', '1551'])

newOutput = combinepseudocode(titles, IDs)
newOutput = [['title1', '1543'], ['title2', '1231'], ['title3', '1551']]

When looking for answers online, I've only come across posts suggesting the np.char.join() or np.concatenate() functions, but the former joins the strings in 2 arrays into a single string, while np.concatenate() only works on integer scalar arrays.

Any help would be appreciated. Thanks!

Jason Li
  • 25
  • 7
  • 1
    `concatenate` can join those 2 arrays, but only one the common dimension, msking a (6,) shape array. That could be reshaped and transposed. But `np.stack` with axis 1, would be easier to use. Sooner or later you need to understand dimsions. You have 2 (3,) array, and want a (3,2) result. – hpaulj Jun 27 '23 at 23:21

1 Answers1

1
np.column_stack((titles, IDs))
Frank Yellin
  • 9,127
  • 1
  • 12
  • 22