Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)

What precisely is the contrast between numpy vstack and column_stack. Perusing the documentation, it looks as though column_stack is an execution of vstack for 1D arrays. Is it a more productive execution? Else, I can't discover an explanation behind having vstack

1 Answer

0 votes
by (26.4k points)

Look at the following code:

>>> np.vstack(([1,2,3],[4,5,6]))

array([[1, 2, 3],

       [4, 5, 6]])

>>> np.column_stack(([1,2,3],[4,5,6]))

array([[1, 4],

       [2, 5],

       [3, 6]])

>>> np.hstack(([1,2,3],[4,5,6]))

array([1, 2, 3, 4, 5, 6])

I've included hstack for examination too. Notice how column_stack stacks along the subsequent measurement though vstack stacks along the primary measurement. The identical to column_stack is the accompanying hstack order:

>>> np.hstack(([[1],[2],[3]],[[4],[5],[6]]))

array([[1, 4],

       [2, 5],

       [3, 6]])

Wanna become a python expert? Join python online course fast!!

Related questions

0 votes
2 answers
0 votes
1 answer
asked Sep 27, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
0 votes
4 answers
asked Apr 11, 2021 in Python by laddulakshana (16.4k points)

Browse Categories

...