Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (19.9k points)

I have a numpy array of shape (224,224,3) after reading a image. However I would like to convert this into a shape of (4,224,224,3).

I would like to kind of repeat the same values.

I am trying to append like shown below this but it doesn't work.


Instead it throws the below error

ValueError: all the input arrays must have same number of dimensions

I expect my output shape to be (4,224,224,3)

Can you guide me on how to do this?

1 Answer

0 votes
by (25.1k points)

Use np.repeat with axis attribute set to 0

like this:

out = np.repeat([image], 4, axis=0)

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Sep 27, 2019 in Python by Sammy (47.6k points)
+5 votes
4 answers
asked May 15, 2019 in Python by Anisha (320 points)

Browse Categories