0

I have an array with the next distribution

array -> shape(878,)

one element inside array

shape(313,313,3)

What I have to do to get the next result?

shape(878,313,313,3)

thanks

4
  • So elements of the array are arrays? Can you provide minimal reproducible example? Commented Jun 21, 2018 at 19:41
  • 1
    If your array elements are 3D arrays of the same size, then it is automatically a 4D array. Commented Jun 21, 2018 at 19:42
  • What's the dtype? Object? Then you have an array of arrays. If so, then this other recent question is relevant: stackoverflow.com/questions/50971123/… Commented Jun 21, 2018 at 19:43
  • Is the dtype of your array object? There are a few ways you could have constructed a 1-D array of length 878 containing arrays, but typically they'd involve a mistake of sizing. Commented Jun 21, 2018 at 19:44

2 Answers 2

1

Assuming that datatypes are not an issue, you should be able to stack them using

np.stack(yourArray)
Sign up to request clarification or add additional context in comments.

Comments

0

Is it an array or a dictionary. But even if you want to change the size , you could directly use np.reshape() for this operation but if you want ot change it in some different way, here is a way:

x = np.zeros((array.size,313,313,3)) # you could replace the numbers with shape of elements

for i in range(array.size):

    x[i] = a[i]

6 Comments

This will be less efficient than letting numpy handle the work for you. Check my answer.
Why do x = np.array([]) and then reassign to x with x = np.zeros((array.size,313,313,3))? :p
Another thing, setting x and then resetting it is a waste.
Beat me to it @JayCalamari
Yeah, I know that that's why I gave it as an alternate solution if he wanted to see how that actually happens or yeah np.vstack() might directly work for him. But thanks for noticing.
|

Your Answer

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.