np.concatenate()与 keras.layer.concatenate()
关于参数axis的取值,说明如下:
import numpy as np
import cv2
from keras.layers import concatenate
from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img
from PIL import Image
import skimage.io as io
import matplotlib.pyplot as plt
import matplotlib.image as mpig
import os
a=np.array([[[1,2],[3,4]],[[5,6],[7,8]]])
b=np.array([[[11,12],[13,14]],[[15,16],[17,18]]])
#去掉第0层括号(最外层),拼接
axis0=np.concatenate([a,b],axis=0)
print(axis0)
print("")
#去掉第0,1层括号,拼接
axis1=np.concatenate([a,b],axis=1)
#axis1=np.concatenate([a,b],axis=-2)
print(axis1)
print("")
#去掉第0,1,2层括号,拼接
axis2=np.concatenate([a,b],axis=2)
#axis2=np.concatenate([a,b],axis=-1)
print(axis2)
运行结果:
D:\SoftWare\Anaconda3\python.exe "C:/Users/ZhangRR/Desktop/unet-master - 副本/Test.py"
Using TensorFlow backend.
# axis=0
[[[ 1 2]
[ 3 4]]
[[ 5 6]
[ 7 8]]
[[11 12]
[13 14]]
[[15 16]
[17 18]]]
# axis=1 (axis=-2)
[[[ 1 2]
[ 3 4]
[11 12]
[13 14]]
[[ 5 6]
[ 7 8]
[15 16]
[17 18]]]
# axis=2 (axis=-1)
[[[ 1 2 11 12]
[ 3 4 13 14]]
[[ 5 6 15 16]
[ 7 8 17 18]]]
Process finished with exit code 0