To learn something by heart :

The ancient Greeks believed incorrectly that intelligence and memory were based in the heart. This explains why, if you learn something by heart, it means that you have memorized it perfectly and can recite it without thinking. “Our teacher asked us to make a speech that we had learned by heart.”