Skip to main content

Matrix: Sum of a column

Answered

Comments

3 comments

  • Official comment
    Simranjit Kaur
    Gurobi Staff Gurobi Staff
    This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?.
  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    Hi Marc,

    Your last attempt is correct.

    The code

    number = matrix.sum(axis=0)
    print(number)

    provides

    1 1
    2 18
    3 9
    4 6
    5 2
    dtype: int64

    , i.e., the sum of each column saved as a \(\texttt{pandas Series}\). You can access the value of the sum of the second column via

    print(number[2])

    which prints

    18

    The index of the columns is defined via your list \(\texttt{cities}\).
    It works the same for rows.

    Best regards,
    Jaromił

    0
  • Marc Schmidt
    Gurobi-versary
    First Comment
    First Question

    Hi Jaromił, 

    thanks for the explanation and solution! It works :) 

     

    0

Post is closed for comments.