Answers for "python last non-zero value in a list"

0

python last non-zero value in a list

>>> import numpy as np
>>> np.max(np.nonzero([-2, -2, 0, 0, 0, 0, 0]))
1 # at index 1
>>> np.max(np.nonzero([-2, 20, -1, 0, 3, 0, 0]))
4 # at index 4
Posted by: Guest on July-14-2021

Code answers related to "python last non-zero value in a list"

Python Answers by Framework

Browse Popular Code Answers by Language