Good day. I have been searching through related posts without getting the ideal solution I would like to find. Let me describe my problem:
I am analyzing texts from a corpus, and extracting features from those texts, then storing the features in an array. Some of these features involve ratios, for example the ratio of masculine pronoun "he" to femenine pronoun "she". The thing is, for some of the variables, the value will be zero, and they will raise ZeroDivisionError.
Since I calculate about 100 of these ratios, wrapping a try / catch exception around every ratio calculation sounds like too cumbersome.
I found out that I can do
#16,RATIO_masculine_femenine
feature_map.append(numOfHe / numOfShe if numOfShe else 0)
But it is still a bit too much laborious. I was wondering if there is a way to state at the beggining of the script that any ZeroDivisionError should be substituted by NaN or 0, or whatever other value that may suit.
Thanks