Skip to main content
reduce <3
Source Link
bobtt
  • 73
  • 8

if you want to use numpy

A=np.array([80, 12, 14, 5, 70, 9, 26, 30, 8, 12, 16, 15]) print [sumreduce(x)lambda forx,y: x in+ [sum(y)], np.array(zip(A,A[1:],A[2:],A[3:])).tolist()],[]) 

output

[111, 101, 98, 110, 135, 73, 76, 66, 51]

if you want to use numpy

A=np.array([80, 12, 14, 5, 70, 9, 26, 30, 8, 12, 16, 15]) print [sum(x) for x in np.array(zip(A,A[1:],A[2:],A[3:])).tolist()] 

output

[111, 101, 98, 110, 135, 73, 76, 66, 51]

if you want to use numpy

A=np.array([80, 12, 14, 5, 70, 9, 26, 30, 8, 12, 16, 15]) print reduce(lambda x,y: x + [sum(y)], np.array(zip(A,A[1:],A[2:],A[3:])).tolist(),[]) 

output

[111, 101, 98, 110, 135, 73, 76, 66, 51]

Source Link
bobtt
  • 73
  • 8

if you want to use numpy

A=np.array([80, 12, 14, 5, 70, 9, 26, 30, 8, 12, 16, 15]) print [sum(x) for x in np.array(zip(A,A[1:],A[2:],A[3:])).tolist()] 

output

[111, 101, 98, 110, 135, 73, 76, 66, 51]