Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- # sample data
- a = np.array(range(75))
- a = a.reshape([1,3,5,5])
- print(a)
- # convert --- version 3
- result = np.dstack(a[0])
- print(result)
- print(result.shape)
- # convert --- version 1
- result = []
- for x1, x2, x3 in zip(a[0,0], a[0,1], a[0,2]):
- q = []
- for z1, z2, z3 in zip(x1, x2, x3):
- q.append([z1, z2, z3])
- result.append(q)
- # ---
- result = np.array(result)
- print(result)
- print(result.shape)
- # convert --- version 2
- result = []
- for x in zip(*a[0]):
- q = []
- for z in zip(*x):
- q.append(z)
- result.append(q)
- # ---
- result = np.array(result)
- print(result)
- print(result.shape)
- # convert --- version 3
- result = [[z for z in zip(*x)] for x in zip(*a[0])]
- # ---
- result = np.array(result)
- print(result)
- print(result.shape)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement