Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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
Comment

PREVIOUS NEXT
Code Example
Python :: get raster corners python 
Python :: Finding Maximum Elements along columns using Python numpy.argmax() 
Python :: mid-point circle drawing 
Python :: python add new key to dictionary 
Python :: cross_val_score scoring parameters types 
Python :: label with list comprehension python 
Python :: split df coliumn 
Python :: python hello world jenkins 
Python :: python create pem file 
Python :: staticmethod vs classmethod python 
Python :: boto3 upload dataframe directly to s3 
Python :: export list to a file python 
Python :: design patterns python 
Python :: python set terminal size 
Python :: fonction nombre premier python 
Python :: python generator function 
Python :: SystemError: error return without exception set 
Python :: print in pytest python 
Python :: python if not none in one line 
Python :: numpy shape 
Python :: django iterate manytomanyfield template 
Python :: decorators in python 
Python :: music distorted on discord 
Python :: python - match two df on a variable with different name 
Python :: date to timestamp python 
Python :: How can I get the output of each layer in Tensorflow 2 
Python :: pip in python 
Python :: pandas get tuples from dataframe 
Python :: np array size 
Python :: Tree: Postorder Traversal 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =