The difference between hstack() and vstack() in numpy

First, numpy.hstack () function

Prototype: numpy.hstack(tup)
where tup is the array of arrays, The arrays must have the same shape, except in the dimensioncorresponding to
axis (the first, by default).
is equivalent to: np.concatenate(tup, axis=1)

Numpy.hstack() is similar to row stacking
program example:
 


>>> a = np.array((1,2,3))

>>> b = np.array((2,3,4))

>>> np.hstack((a,b))

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


>>> a = np.array([[1],[2],[3]])

>>> b = np.array([[2],[3],[4]])

>>> np.hstack((a,b))

array([[1, 2],

       [2, 3],

       [3, 4]])

Second, numpy.vstack () function

Prototype: numpy.vstack(tup)

Equivalent to: np.concatenate(tup, axis=0) iftup contains arrays thatare at least 2-dimensional.

Numpy.vstack() is similar to column stacking

Program example:


>>> a = np.array([1, 2, 3])

>>> b = np.array([2, 3, 4])

>>> np.vstack((a,b))

array([[1, 2, 3],

       [2, 3, 4]])


>>> a = np.array([[1], [2], [3]])

>>> b = np.array([[2], [3], [4]])

>>> np.vstack((a,b))

array([[1],

       [2],

       [3],

       [2],

       [3],

       [4]])

 

 

 

Intelligent Recommendation

[Numpy]stack(), hstack(), vstack(), concatenate()

Part of the information comes from the Internet table of Contents 0. Axis value 1. stack() 2. hstack() 3. vstack() 4. concatenate() 0. Axis value In numpy arrays are marked with [], axis=0 c...

About Numpy Stack, Hstack, VStack

stack Matrix of the same dimension hstack Hstack and VStack are for column vector and matrix vstack...

Simple understanding of hstack and vstack in Numpy

learning target: Understand the meaning of Hstack and VStack by comparing the results of Hstack (Horizontal-Stack) and Vstack (Vertical-Stack) by comparing one-dimensional / two-dimensional matrix. Co...

Detailed explanation of stack(), hstack(), and vstack() functions in Numpy

These three functions have some similarities. They are stacked arrays. The most difficult thing to understand is the stack() function. I checked the official documentation of numpy, and I watched a fe...

Numpy stack, vstack, hstack, concatenate in python

np.stack Stacking on a dimension axis=0 is the same as the original array axis=1 Results are as follows array([[1, 5], [2, 6], [3, 7], [4, 8]]) Pack the data in which dimension as a whole, then stack ...

More Recommendation

Hstack(), vstack(), stack(), concatenate() functions in numpy

This article mainly introduces several commonly used functions in numpy, including hstack(), vstack(), stack(), and concatenate(). 1、concatenate() Let's first introduce the most versatile concatenate(...

Numpy the stack (), using hstack (), vstack () function method

stack () and hstack (), vstack () different, the former is coupled to the stack array (join), The latter two are connected in series (concatenation), You can taste. 1. stack () function Couplings acco...

numpy python in the stack, vstack, hstack, concatenate usage

Do some of the more simple explanation is a function np.stack () in python's numpy library, read some of the blog written by someone else feel too complicated, and then have some understanding of thei...

Introduction to numpy functions hstack, vstack, dstack

Vstack, hstack, and dstack are all used to merge several small arrays into one large array. The difference between them is that the elements of the small array are arranged in a different order in the...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top