Python Practice › NumPy Programs › Program 63

1-D arrays as columns

EasyNumPy Programs · 63 of 100

Write a NumPy program to combine two 1-D arrays as columns of a 2-D array.

Advertisement
Input
(3, 8, 5), (4, 0, 7)
Output
[[3 4]
 [8 0]
 [5 7]]

Approach

  1. np.column_stack.

Solution

Python
import numpy as npprint(np.column_stack(((3, 8, 5), (4, 0, 7))))
Output
[[3 4]
 [8 0]
 [5 7]]

Learn the concept

New to this topic? Read the lesson, then come back.

More numpy programs

← All 100 NumPy Programs

Leave a Comment