【发布时间】:2020-06-13 21:46:45
【问题描述】:
我想通过复制最后一个元素将(z,x,y,1)形numpy数组变成(z,x,y,3)形numpy数组?
举个例子
import numpy as np
# The shape is (1,2,2,1) (that is z=1, x=2, y=2)
a = np.array([[[[1], [2]],[[3], [4]]]])
print(a.shape)
# I want to make it (1,2,2,3) by duplicating the last element 3 times as follow
a = np.array([[[[1,1,1], [2,2,2]],[[3,3,3], [4,4,4]]]])
print(a.shape)
所以给定一个形状为(z,x,y,1) 的numpy 数组a,如何通过复制最后一个元素使其成为(z,x,y,3) numpy 数组?
【问题讨论】: