Solved by ptrblck in post #2 
              
              
                Would selecting the desired values in a and b before applying the division work? 
E.g. you could create a mask first and use it to index both tensors where the condition would be b!=0.