1

I have a numpy array that looks like:

[0,0,0,1,2,0,0,3,0,0,9]

I want to transform this array into:

[1,1,1,1,2,3,3,3,9,9,9]

As you could see all zero values have been replaced with the next non zero value. Is there a way with numpy where I could do this?

Amanda
  • 2,013
  • 3
  • 24
  • 57

0 Answers0