0

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.

asked Apr 30, 2019 at 18:35
5
  • 1
    docs.scipy.org/doc/numpy/reference/generated/… Commented Apr 30, 2019 at 18:36
  • you means (6000, 32, 32, 3) -> (32, 32, 3, 6000)? Commented Apr 30, 2019 at 18:43
  • Not exactly, the way data was generated the array is a numpy object array. data.shape prints (6000,) and data[1].shape print (32,32,3). I want data.shape to print (60000,32,32,3). Commented Apr 30, 2019 at 18:47
  • Try np.stack. Commented Apr 30, 2019 at 19:02
  • concatenate and reshape worked Commented Apr 30, 2019 at 19:09

1 Answer 1

1

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)

answered Apr 30, 2019 at 18:46

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.