Let’s see a program to convert 1-D arrays as columns into a 2-D array using NumPy library in Python. So, for solving this we are using numpy.column_stack() function of NumPy. This function takes a sequence of 1-D arrays and stack them as columns to make a single 2-D array.
Syntax : numpy.column_stack(tuple)
tup : [sequence of ndarrays] Tuple containing arrays to be stacked. The arrays must have the same first dimension.
Return : [stacked 2-D array] The stacked 2-D array of the input arrays.
Now, let’s see an example:
[['Geeks' 'my'] ['for' 'name'] ['geeks' 'sachin']]
[[1 5] [2 6] [3 7] [4 8]]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.