gd13
gd13

Reputation: 55

How to convert array of numpy objects to an array containing the elements of every object?

I have an numpy objects array with shape (60000,) and each of the 60000 elements is a (32,32,3)array. My question is how to convert the (60000,) array to a (32,32,3,60000) array.

Upvotes: 0

Views: 77

Answers (1)

aghriss
aghriss

Reputation: 54

import numpy as np

class Obj():
    def __init__(self,i):
        self.i = i

l = np.array([np.array([Obj(i) for i in range(64*3)]).reshape(8,8,3)
 for _ in range(100)])

print(l.shape)
#Output: (100, 8, 8, 3)

print(np.transpose(l,(1,2,3,0)).shape)
#Output: (8, 8, 3, 100)

Upvotes: 1

Related Questions