Join 2 1-dimensional numpy string arrays into a larger 2 dimensional array

Advertisements

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!

>Solution :

np.column_stack((titles, IDs))

Leave a ReplyCancel reply