2021年3月25日星期四

make list in list dynamic in python, problem?

i want to make a list by combining the results of n. but when the x values are different, it creates a new list. However, if the x value is the same, it will be in 1 list

My code is like this

muy = [[1,2,3],[4,5,6],[7,8,9]]  # will = []  for x in muy:      for y in muy:          if x != y:              print(x, " ", y)              m = np.subtract(x, y)              n = sum(m)              print(m)              print(n)  

the result is like this

[1, 2, 3]   [4, 5, 6]  [-3 -3 -3]  -9  [1, 2, 3]   [7, 8, 9]  [-6 -6 -6]  -18  [4, 5, 6]   [1, 2, 3]  [3 3 3]  9  [4, 5, 6]   [7, 8, 9]  [-3 -3 -3]  -9  [7, 8, 9]   [1, 2, 3]  [6 6 6]  18  [7, 8, 9]   [4, 5, 6]  [3 3 3]  9  

the result what i want is like this:

[[-9,-18][9,-9][18,9]]  

what should i do?

https://stackoverflow.com/questions/66810876/make-list-in-list-dynamic-in-python-problem March 26, 2021 at 12:00PM

没有评论:

发表评论