This forced me to go down a transpose() in multiple dimensions rabbit hole that’s worth documenting. First, here’s code that takes some tiny images in an array and transposes them:
import numpy as np
img_list = [
# image 1
[[[10, 20, 30],
[11, 21, 31],
[12, 22, 32],
[13, 23, 33]],
[[255, 255, 255],
[48, 45, 58],
[101, 150, 205],
[255, 255, 255]],
[[255, 255, 255],
[43, 56, 75],
[77, 110, 157],
[255, 255, 255]],
[[255, 255, 255],
[236, 236, 238],
[76, 104, 139],
[255, 255, 255]]],
# image 2
[[[100, 200, 300],
[101, 201, 301],
[102, 202, 302],
[103, 203, 303]],
[[159, 146, 145],
[89, 74, 76],
[207, 207, 210],
[212, 203, 203]],
[[145, 155, 164],
[52, 40, 36],
[166, 160, 163],
[136, 132, 134]],
[[61, 56, 60],
[36, 32, 35],
[202, 195, 195],
[172, 165, 177]]]]
np_imgs = np.array(img_list)
print("np_imgs shape = {}".format(np_imgs.shape))
imgs = np.transpose(img_list, (0, 2, 1, 3))
print("imgs shape = {}".format(np_imgs.shape))
#imgs = np.array(imgs) / 255
print("pix 0: \n{}".format(np_imgs[0]))
print("transposed pix 0: \n{}".format(imgs[0]))
print("\n------------------------\n")
print("pix 1: \n{}".format(np_imgs[1]))
print("transposed pix 1: \n{}".format(imgs[1]))
You must be logged in to post a comment.