Skip to main content

Matrix: Sum of a column

Answered

Comments

2 comments

  • 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

Please sign in to leave a comment.