←back to thread

I don't like NumPy

(dynomight.net)
480 points MinimalAction | 1 comments | | HN request time: 0.196s | source
1. actinium226 ◴[] No.44000698[source]
For the first example:

    import numpy as np
    A = np.random.random((100, 5, 5))
    b = np.random.random((100, 5, 1))
    x = np.linalg.solve(A, b)
Admittedly the documentation is a little hard to read if you just look at 'type' for b, but then it says "Returned shape is (..., M) if b is shape (M,) and (..., M, K) if b is (..., M, K) where ... is broadcasted between a and b"

So you have to make sure your b vector is actually a matrix and not a vector (if K=1 for your case).