Array is specified
A1,1 A1,2 A1,3 A1,4 A1,5 A1,6 ... A1,n Need to withdraw
A1,2-A1,1 A1,3-A1,1 A1,3-A1,2 A1,4-A1,1 A1,4-A1,2 A1,4-A1,3 A1,5-A1,1 A1,5-A1,2 A1,5-A1,3 A1,5-A1,4 A1,6-A1,1 A1,6-A1,2 A1,6-A1,3 A1,6-A1,4 A1,6-A1,5 ... ... ... ... ... ... A1,n-A1,1 A1,n-A1,2 A1,n-A1,3 A1,n-A1,4 A1,n-A1,5 A1,n-A1,n-1 My algorithm
ls = list(range(1, 6)) res = [] for i, item in enumerate(ls): buf = [item1 - item for item1 in ls[i+1:]] res.append(buf) for s in range(len(ls)-1): print(res[s]) I get
Displays data in a horizontal scan.
[1, 2, 3, 4] [1, 2, 3] [1, 2] [1] instead of vertical
[1] [2] [1] [3] [2] [1] [4] [3] [2] [1] but it's not scary when working with arrays, so I go further
Instead
ls = list(range(1, 6)) which was given to test the health of the cycle I fill in the data from the file
In this case, I import the values as str
with open('Test3.csv') as f: ls = f.read() res = [] for i, item in enumerate(ls): buf = [item1 - item for item1 in ls[i+1:]] res.append(buf) for s in range(len(ls)-1): print(res[s]) Also tried so
In this case, I import the values as list
ls = open('Test3.csv').readlines() res = [] for i, item in enumerate(ls): buf = [item1 - item for item1 in ls[i+1:]] res.append(buf) for s in range(len(ls)-1): print(res[s]) The same error is issued unsupported operand type (s) for -: 'str' and 'str'
As I understand this error, for the operation of the loop (for ...), integer values are needed so that an operation inside the loop can be performed.
I can only understand how to mitigate this error and all
Uraa happened
ls = open('Test3.csv').readlines() res = [] for i, item in enumerate(ls): buf = [int(item1) - int(item) for item1 in ls[i+1:]] res.append(buf) for s in range(len(ls)-1): print(res[s])