Could you check the type of all_loss[phase] and in case it’s containing more than one object, the type of the first object?
Based on the error message it seems that all_loss[phase] is already containing a numpy array, which will raise this error.