nonetype - How do I convert all python operations involving None to None values? -
i want mathematical operations involving 1 or more none variables return none.
example:
a = none b = 7 a*b
i want last line return none, instead gives me error:
typeerror: unsupported operand type(s) *: 'nonetype' , 'int'
i understand why error exists , that, there way force result none
?
background: have few functions mine data , return value, called diff
. later on multiply or add diff
few things meaningful information, not of original data contains useful diff
, have set return diff = none
in these cases. want able skip on these points when i'm plotting results. python seems have no trouble skipping on none
elements in array when i'm plotting, i'd have results of operations none
.
instead of trying force mathematical operations contain arbitrary other value return arbitrary other value, use nan
, designed sort of purpose:
>>> nan = float("nan") >>> 7 * nan nan >>> 7 + nan nan
a nan
correctly cascade throughout mathematical operations.
a plotting library understand nan
, omit them @ plot time. if not, replacement of nan
none
prior plotting.
Comments
Post a Comment