Я смог сделать это с помощью предложения @DatHydroGuy о numpy.rot90
.Вот примеры того, как это сделать.Обратите внимание, что сначала я группирую значения x, y, z в кортежах в списке.Затем создайте пустой массив кортежей в виде объектов, поверните его, а затем сведите массив в список, используя понимание списка.
import numpy as np
a = [5, 0, 3, 3, 7, 9, 3, 5, 2, 4, 7, 6, 8, 8, 1, 6, 7, 7, 8, 1, 5, 9, 8, 9, 4, 3, 0, 3, 5, 0, 2, 3, 8, 1, 3, 3]
sh = (4,3) # Shape
a_tup = [tuple(a[i:i+3]) for i in range(0, len(a), 3)] # Group list into tuples (x,y,z)
print(a_tup)
# [(5, 0, 3), (3, 7, 9), (3, 5, 2), (4, 7, 6), (8, 8, 1), (6, 7, 7), (8, 1, 5), (9, 8, 9), (4, 3, 0), (3, 5, 0), (2, 3, 8), (1, 3, 3)]
b=np.empty(sh, dtype=object) # Initialize numpy array with object as elements (for the tuples) and your shape sh
for j in range(sh[1]): # Assign tuples from list to positions in the array
for i in range(sh[0]):
b[i,j] = a_tup[i+j]
print(b)
# [[(5, 0, 3) (3, 7, 9) (3, 5, 2)]
# [(3, 7, 9) (3, 5, 2) (4, 7, 6)]
# [(3, 5, 2) (4, 7, 6) (8, 8, 1)]
# [(4, 7, 6) (8, 8, 1) (6, 7, 7)]]
c = np.rot90(b)
print(c)
# [[(3, 5, 2) (4, 7, 6) (8, 8, 1) (6, 7, 7)]
# [(3, 7, 9) (3, 5, 2) (4, 7, 6) (8, 8, 1)]
# [(5, 0, 3) (3, 7, 9) (3, 5, 2) (4, 7, 6)]]
print([item for sublist in c.flatten() for item in sublist]) # Flatten the numpy array of tuples to a list of numbers
# [3, 5, 2, 4, 7, 6, 8, 8, 1, 6, 7, 7, 3, 7, 9, 3, 5, 2, 4, 7, 6, 8, 8, 1, 5, 0, 3, 3, 7,9, 3, 5, 2, 4, 7, 6]