I think the problem here is that it creates large dense intermediate arrays, which can result to out-of-memory situations --- sparse matrices e.g. of size `1e5x1e5` are quite common, so dense intermediate arrays should be avoided when possible.

To avoid the import loop, you can either add the import inside the function, or copy the one-liner from spdiags,
`dia_matrix((other.ravel(), [0]), shape=self.shape)`