I have a matrix (using numpy), user enters number of rows and columns. After going through some FOR loops, user enters elements, of course depending on what number of rows and columns did he/she has chosen.
Now I need to find a sum of negative elements for every row below row 7 and output this every row sum, right after the exact row. Here is my code (even though code for this last thing doesn't work)
import numpy as np
A = list()
n = int(input("How many rows: "))
m = int(input("How many columns: "))
for x in range(n):
if n <= 0 or n>10:
print("Out of range")
break
elif m <= 0 or m>10:
print("Out of range")
break
else:
for y in range(m):
num = input("Element: ")
A.append(int(num))
shape = np.reshape(A,(n,m))
for e in range(n < 7):
if e < 0:
print(sum(e))
print(shape)
If as a user, I will enter 3 rows and 3 columns, I can get something like this (I'll enter some numbers to explain what I need):
[-1, 2, -3]
[-4, 5, -6]
[-7, -8, 9]
I should get something like this:
[-1, 2, -3] Sum of Negative Elements In This Row (Till 7th) [-4]
[-4, 5, -6] Sum of Negative Elements In This Row (Till 7th) [-10]
[-7, -8, 9] Sum of Negative Elements In This Row (Till 7th) [-15]
Also please don't forget I need it only till row 7, even if it will have more rows, I am not interested in them.