My question:
For example, my text file is call 'feed.txt'. and for inside, it likes that:
2 # two means 'there are two matrix in this file'
3 # three means 'the below one is a 3*3 matrix'
1 8 6
3 5 7
4 9 2
4 # four means 'the below one is a 4*4 matrix'
16 3 2 13
5 10 11 8
9 6 7 12
4 15 14 1
There are two matrix in side this file. [[1,8,6],[3,5,7],[4,9,2]]
and [[16,3,2,13],[5,10,11,8],[9,6,7,12],[4,15,14,1]]
.
I want to know how can I use these two matrix in Python as a list which like
list_=[[1, 8, 6], [3, 5, 7], [4, 9, 2]]
and then I can get sam(list_[0])=15
.
also. there are three rows in
list_=[[1, 8, 6], [3, 5, 7], [4, 9, 2]]
and I want to do the sum of each row. So I did
list_=[[1, 8, 6], [3, 5, 7], [4, 9, 2]]
for i in range(len(list_)):
sum_=sum(list_[i])
print(sum_)
but I cannot get three numbers, I only get one number, why ?
See Question&Answers more detail:
os