I was trying to install the CUDA Toolkit from the NVDIA website. After I ran
$ sudo sh cuda_10.1.105_418.39_linux.run
it began the installation, and it finished with errors, which said that I was using X drivers instead of NVIDIA ones, so I followed the first 40 seconds of this video:
https://www.youtube.com/watch?v=8Xy1Uqq9Hbk&t=45s
That is, I went to Additional Drivers and changed from "Using X.Org X server" to "NVDIA binary driver, version 384.130". Then I restarted and now the login page of Ubuntu is displayed with a different resolution, and when I try to log in it reboots and comes back to the log in page.
I have read that the problem is most probably due to installing drivers running a .run file, and that I should purge nvidia and install it again from the shell command line. However, I don't know which version I should install and I don't want to mess it up more.
I don't know if I wrote enough information. If you need more, please tell me.