Magnet or electromagnet