numpy.column_stack()
函數用於將一維數組作為列堆疊到二維數組中,它采用一維數組序列並將它們堆疊為列以構成一個二維數組。二維陣列堆疊as-is,就像hstack
函數。
用法: numpy.column_stack(tup)
參數:
tup :[ndarrays的序列]包含要堆疊的數組的元組。數組必須具有相同的第一維。
Return :[堆疊的二維數組]輸入數組的堆疊的二維數組。
代碼1:
# Python program explaining
# column_stack() 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
out_arr = geek.column_stack((in_arr1, in_arr2))
print ("Output stacked array:\n ", out_arr)
輸出:
1st Input array: [1 2 3] 2nd Input array: [4 5 6] Output stacked array: [[1 4] [2 5] [3 6]]
代碼2:
# Python program explaining
# column_stack() 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
out_arr = geek.column_stack((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 4 5 6] [-1 -2 -3 -4 -5 -6]]
相關用法
注:本文由純淨天空篩選整理自jana_sayantan大神的英文原創作品 numpy.column_stack() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。