Python itself is way too slow for any serious compute tasks, so I’m going to assume you’re already using NumPy to speed it up. Even so I’d look into rewriting it in some compiled language if feasible. There are CPU SIMD instructions for accelerating certain type of operations on matrices. Supposedly NumPy should be able to make use of them, but I don’t have any experience with that. Your 5600 for example supports 256-bit AVX2 operations.
In case you have already ruled out possible code/runtime optimizations and have concluded the only way forward is more cores, the cheapest upgrade would be upgrading to 5900/5950X for 12 or 16 cores.
There are some Optane drives with m.2 interface like P1600X. Optane may not beat bandwidth records, but their low latency makes them ideal for when you have to do lots of smaller read/write operations like when using databases.