'Concatenate two List in a 2D Array in Python with Numpy
So, i have 2 list that i want to concatenate with numpy. For now, i'm tring to do something like this :
LeGraphiqueMatLab = np.array([LesDatesMatLab, LeGraphique], dtype=np.float64)
But it gives me an error saying : "ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (2, 2) + inhomogeneous part."
Do I need to use np.array on each list first and then try to add them ?
Thanks
Solution 1:[1]
You can use np.concatenate like that:
a = [1, 2]
b = [5, 6]
np.concatenate((a, b))
#output
array([1, 2, 5, 6])
Solution 2:[2]
As Phoenix stated, you can use np.concatenate(); however, I have a feeling that LesDatesMatLab & LeGraphique may have different shapes as the error stated "inhomogeneous".
Without seeing what LesDatesMatLab & LeGraphique are, it's hard to say but try Phoenix's answer - if error persists, use LesDatesMatLab.shape & LeGraphique.shape to check if the shapes are both consistent. If not, you may need to use np.reshape() to make them consistent.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Phoenix |
| Solution 2 |
