2

I am dealing with numpy arrays of shape (nb, 128, 128, 3) where nb is a variable quantity. I am looking for a way to concatenate them.

An example input: Two numpy arrays with shapes (1088, 128, 128, 3) and (823, 128, 128, 3).

Now, the shape of the output array after the desired operation should be (1911, 128, 128, 3).

Note: The number of numpy arrays to be concatenated could be variable.

Thank you for your time in advance.

2
  • concatenate Commented Jan 11, 2020 at 16:10
  • Might be a bit expensive ! Commented Jan 11, 2020 at 19:12

2 Answers 2

1

If you have variable no. of arrays in a list, there also np.concatenate does the trick.

listOfArrays = [a, b, c,.... ,n]
np.concatenate(listOfArrays, axis=0)
Sign up to request clarification or add additional context in comments.

Comments

1

Consider the following:

import numpy as np

# your arrays
A = np.array(...)
B = np.array(...)

C = np.concatenate((A, B))

3 Comments

Thanks for your inputs. But what if instead of having two numpy arrays I have n?
@WarrenWeckesser, agree.
@S.P The tuple argument of concatenate can be of length n.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.