0

I have been searching all over the internet and I can't seem to find how to answer my homework question. The user should enter matrices and indicate whether the matrices are to be added or subtracted. You should be able to add or subtract as many matrices as you wish without having to re-enter the previous solution. I am a beginner with python and am not sure how to go about this. All I have so far is

    #Ask the user to input a matrix
    print ('Enter your row one by one (pressing enter between each row). 
    To terminate, enter an empty row.')
    M = []

    #Allow them to determine dimensions
    while True:
        r = input ('Next row > ')
        if not r.strip (): # Empty input
            break
        M.append(list(map(int, r.split())))

    #Display the matrix
    print('M =', M)
  • 1
    Try taking the first input from the user as the number of matrices to be added/subtracted, then their dimensions, then the actual values. The next step, check the dimensions of all matrices (they need to be equal for addition/subtraction) and then do the final addition/subtraction using standard libs/something like numpy – Vivek Kalyanarangan Feb 28 '18 at 06:35
  • use numpy or panda https://stackoverflow.com/questions/18646076/add-numpy-array-as-column-to-pandas-data-frame – om tripathi Feb 28 '18 at 06:36

0 Answers0