0

I have the following two list of lists and I want to substract every item from a from the corresponding item in b:

a = [[8.5], [9.3], [8.2]]
b = [[7.4], [2.3], [3.4]]

So the output should be

c = [[1.1], [7], [4.8]]

It seems to be very simple, but I am struggling with it. Does somebody have a solution?

maybeyourneighour
  • 494
  • 2
  • 4
  • 13

1 Answers1

1

Create flat list of both first

flat_list = [item for sublist in a for item in sublist]

then convert to numpy array

a= np.array(a)
b = np.array(b)

then make list of lists [i for i in a] and similarly b

Fasty
  • 784
  • 1
  • 11
  • 34
  • why to create a flat list, then use numpy to substract, then change back to OP output format, when all this you can do in single list comprehension ? – sahasrara62 Aug 07 '19 at 08:58