numpy.vstack()函數用於垂直堆疊輸入數組的序列以形成單個數組。
用法: numpy.vstack(tup)
參數:
tup :[ndarrays的序列]包含要堆疊的數組的元組。除第一軸外,所有陣列的形狀都必須相同。
Return :[stacked ndarray]輸入數組的堆棧數組。
代碼1:
# Python program explaining
# vstack() function
import numpy as geek
# input array
in_arr1 = geek.array([ 1, 2, 3] )
print ("1st Input array:\n", in_arr1)
in_arr2 = geek.array([ 4, 5, 6] )
print ("2nd Input array:\n", in_arr2)
# Stacking the two arrays vertically
out_arr = geek.vstack((in_arr1, in_arr2))
print ("Output vertically stacked array:\n ", out_arr)
輸出:
1st Input array: [1 2 3] 2nd Input array: [4 5 6] Output vertically stacked array: [[1 2 3] [4 5 6]]
代碼2:
# Python program explaining
# vstack() function
import numpy as geek
# input array
in_arr1 = geek.array([[ 1, 2, 3], [ -1, -2, -3]] )
print ("1st Input array:\n", in_arr1)
in_arr2 = geek.array([[ 4, 5, 6], [ -4, -5, -6]] )
print ("2nd Input array:\n", in_arr2)
# Stacking the two arrays vertically
out_arr = geek.vstack((in_arr1, in_arr2))
print ("Output stacked array:\n ", out_arr)
輸出:
1st Input array: [[ 1 2 3] [-1 -2 -3]] 2nd Input array: [[ 4 5 6] [-4 -5 -6]] Output stacked array: [[ 1 2 3] [-1 -2 -3] [ 4 5 6] [-4 -5 -6]]
相關用法
注:本文由純淨天空篩選整理自jana_sayantan大神的英文原創作品 numpy.vstack() in python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。