3 ms·
In python, I hate hate hate having to do import numpy import scipy.sparse import scipy.sparse.linalg just to begin writing something. You cannot
by enriquto 7y ago
In python, I hate hate hate having to do
import numpy
import scipy.sparse
import scipy.sparse.linalg
just to begin writing something.
You cannot create a literal array without calling a function. You cannot concatenate arrays without calling a function, and moreover this function has a different name depending on whether your arrays are full or sparse. The @ notation for matrix products is horrendous (and .dot is even worse). Arrays are not first-class objects of the language, and you have to use an external library. This is more infuriating by the fact that other, more complex data structures like dictionaries or strings are natively supported, even if they are mostly useless for numerical computation.
Compare the clean matrix flipping in octave
z = [ kron(speye(rows(y)), x) ; kron(y, speye(cols(x))) ]
to the python monstrosity
z = scipy.sparse.vstack([
scipy.sparse.kron(scipy.sparse.eye(y.shape[0]), x),
scipy.sparse.kron(y, scipy.sparse.eye(x.shape[1]))
])
- mlevental 7y agolol don't blame the tools for your ignorance of them from scipy.sparse import eye, kron from scipy.spare import vstack as vs z = vs([ kron(eye(y.shape[0]), x), kron(y, eye(x.shape[1])) ])