Может быть, это может помочь вам
import numpy as np
# This is your iamge, for example.
example_image = np.array([1,1,1,2,2,2,3,3,3])
print(example_image)
# this is gonna be the same image but in other shape
example_image = np.reshape(example_image,(3,3))
print(example_image)
Этот код делает это:
# first print
[1 1 1 2 2 2 3 3 3]
# second print
[[1 1 1]
[2 2 2]
[3 3 3]]
хорошо, давайте попробуем использовать некраскованную матрицу, например:
import numpy as np
# This is your iamge, for example.
example_image = np.array([1,1,1,1,2,2,2,2,3,3,3,3])
print(example_image)
# this is gonna be the same image but in other shape
# 3 Row, 4 Columns
example_image = np.reshape(example_image,(3,4))
print(example_image,"\n")
# or maybe this...
example_image = np.array([1,1,1,1,2,2,2,2,3,3,3,3])
# 3 layers, 2 Row, 2 Columns
example_image = np.reshape(example_image,(3,2,2))
print(example_image[0], "\n\n" ,example_image[1], "\n\n" ,example_image[2])
Результаты:
#original
[1 1 1 1 2 2 2 2 3 3 3 3]
#First reshape
[[1 1 1 1]
[2 2 2 2]
[3 3 3 3]]
# Second Reshape
[[1 1]
[1 1]]
[[2 2]
[2 2]]
[[3 3]
[3 3]]