[英]How to reshape image from (n,m,4) to (n,m,3) in python?
I have an image value like the following: 我的图像值如下所示:
A = [[[ 7, 23, 0, 255],
[ 14, 25, 1, 255],
[ 23, 26, 1, 255],
[ 49, 41, 33, 255],
[ 43, 37, 30, 255],
[ 42, 33, 25, 255]],
[[ 59, 69, 59, 255],
[ 77, 83, 72, 255],
[ 86, 91, 84, 255],
[ 16, 16, 8, 255],
[ 9, 7, 2, 255],
[ 1, 0, 0, 255]]]
print(np.array(A).shape) ## (3,6,4)
I want to reshape it like (3,6,3)
such that I want to skip 255
for the matrix. 我想像(3,6,3)
那样重塑它,以便跳过255
矩阵。
How can I do? 我能怎么做?
You need slicing not reshape which keeps all elements but changes the shape of the array; 您需要切片而不是重塑切片,这样可以保留所有元素,但可以改变数组的形状; For your case, simply drop the last element along the third axis: 对于您的情况,只需沿第三个轴放置最后一个元素:
np.array(A)[:,:,:-1].shape
# (2, 6, 3)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.