0

How to concatenate numpy array?

I want to concatenate all numpy arrays.

for example, there are some numpy array as below

a = numpy.array([1,2,3])
b = numpy.array([4,5,6])
c = numpy.array([7,8,9])

To concatenate them all.

we need a extra empty variable.

tot = numpy.concatenate(tot, a)
tot = numpy.concatenate(tot, b)
tot = numpy.concatenate(tot, c)

how to declare tot empty variable ? (if there are too many arrays?)

1
  • What do you expect? [[1,2,3],[4,5,6],[7,8,9]] or [1,2,3,4,5...].? concatenate accepts a list of arrays - but pay close attention to your dimensions. Commented Sep 19, 2020 at 20:02

3 Answers 3

1

You need them in a tuple:

>>> tot = numpy.concatenate((a,b,c))
>>> tot
array([1, 2, 3, 4, 5, 6, 7, 8, 9])
Sign up to request clarification or add additional context in comments.

Comments

0

Not an answer to your question but would like to propose it of curiosity

a = numpy.array([1,2,3])
b = numpy.array([4,5,6])
c = numpy.array([7,8,9])

d = numpy.array(list(a)+list(b)+list(c))

Comments

0
tot = np.concatenate([a,b,c], axis=0)

Read the Documentation

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.