close

How to merge multiple arrays in python?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to merge multiple arrays in python in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to merge multiple arrays in python?

  1. How to merge multiple arrays in python?

    And now it will copy the data out of day1 and into the new allDays array. This will double your memory usage, so perhaps best to issue a del day1 after each addition to allDays.

  2. to merge multiple arrays in python

    And now it will copy the data out of day1 and into the new allDays array. This will double your memory usage, so perhaps best to issue a del day1 after each addition to allDays.

Method 1

When you do

allDays=[]
allDays.append(day1)
allDays.append(day2)

You are making a list of pointers to existing data, rather than repackaging the data. You could do:

allDays=[]
allDays.append(day1[:])
allDays.append(day2[:])

And now it will copy the data out of day1 and into the new allDays array. This will double your memory usage, so perhaps best to issue a del day1 after each addition to allDays.

Having said all that, if you use Pandas (usually recommended for time series data) or Numpy, this whole thing would be a lot quicker and use a lot less memory. Numpy arrays cannot hold pointers like python lists can, so the copy there is implied. Hope that clears some things up for you 🙂

Method 2

Use allDays = np.concatenate((day1, day2)).

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read