Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dataframe with all possible Sums of two arrays in Python

Lets say i have two arrays

array_1 = [10,20,30]
array_2 = [50,60,70]

Dataframe i need as Output:

        10   20   30
50      60   70   80
60      70   80   90
70      80   90  100
like image 575
Andre Avatar asked Jan 02 '23 03:01

Andre


1 Answers

Use outer addition

>>> np.add.outer(array_1, array_2)

To create the data frame:

pd.DataFrame(arr, columns=array_2, index=array_1)
like image 132
rafaelc Avatar answered Jan 05 '23 00:01

rafaelc