1

How do I combine all of these numpy arrays?

array([[0.00938241, 0.        , 0.        , 0.        , 0.        ,
        0.        , 0.        , 0.        , 0.        , 0.        ,
        0.        , 0.        , 0.        ],
       [0.        , 0.00902791, 0.        , 0.        , 0.        ,
        0.        , 0.        , 0.        , 0.        , 0.        ,
        0.        , 0.        , 0.        ],
       [0.        , 0.        , 0.00744846, 0.        , 0.        ,
        0.        , 0.        , 0.        , 0.        , 0.        ,
        0.        , 0.        , 0.        ],
       [0.        , 0.        , 0.        , 0.00607864, 0.        ,
        0.        , 0.        , 0.        , 0.        , 0.        ,
        0.        , 0.        , 0.        ],
       [0.        , 0.        , 0.        , 0.        , 0.00508451,
        0.        , 0.        , 0.        , 0.        , 0.        ,
        0.        , 0.        , 0.        ],
       [0.        , 0.        , 0.        , 0.        , 0.        ,
        0.00731141, 0.        , 0.        , 0.        , 0.        ,
        0.        , 0.        , 0.        ],
       [0.        , 0.        , 0.        , 0.        , 0.        ,
        0.        , 0.00747849, 0.        , 0.        , 0.        ,
        0.        , 0.        , 0.        ],
       [0.        , 0.        , 0.        , 0.        , 0.        ,
        0.        , 0.        , 0.00603218, 0.        , 0.        ,
        0.        , 0.        , 0.        ],
       [0.        , 0.        , 0.        , 0.        , 0.        ,
        0.        , 0.        , 0.        , 0.00502514, 0.        ,
        0.        , 0.        , 0.        ],
       [0.        , 0.        , 0.        , 0.        , 0.        ,
        0.        , 0.        , 0.        , 0.        , 0.00823613,
        0.        , 0.        , 0.        ],
       [0.        , 0.        , 0.        , 0.        , 0.        ,
        0.        , 0.        , 0.        , 0.        , 0.        ,
        0.00828131, 0.        , 0.        ],
       [0.        , 0.        , 0.        , 0.        , 0.        ,
        0.        , 0.        , 0.        , 0.        , 0.        ,
        0.        , 0.00833615, 0.        ],
       [0.        , 0.        , 0.        , 0.        , 0.        ,
        0.        , 0.        , 0.        , 0.        , 0.        ,
        0.        , 0.        , 0.0088979 ]])

I want to get

array([0.00938241, 0.00902791        , 0.00744846        , 0.00607864        , 0.00508451        ,
        0.00731141        ,...])

as my ouput i.e. I just want to sum them all up into one array. How do I do this with more than two arrays? I don't see any documentation that addresses this...

6
  • Have you tried arr.sum(0)? Commented Sep 30, 2019 at 1:28
  • 1
    I only see one array. Are you trying to sum along an axis? Commented Sep 30, 2019 at 1:28
  • Yes I am. That's right. Commented Sep 30, 2019 at 1:34
  • How did you even get this array? It looks like a 2D array with the data you want on the main diagonal. It's very likely that you did something wrong, or at least very suboptimal, while creating this array, and you should probably change the code that created it instead of trying to post-process the output. Commented Sep 30, 2019 at 1:35
  • 1
    A good starting point is trying to understand what you have. As pointed out this is one array (not many). Print arr.shape and arr.dtype. Then the task of adding rows or columns becomes clearer. Or getting the diagonal. Commented Sep 30, 2019 at 1:58

1 Answer 1

1

just do sum along axis 1

also use np.array instead of pd.Dataarray which is not defined

arr.sum(axis=1)
Sign up to request clarification or add additional context in comments.

1 Comment

it is same as the array is diagonal square

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.