Are you getting this error also using my code snippet or only yours?
In the latter case, it seems you are still adding a numpy array to all_loss, so would still have to narrow down the offending line of code.