Note that there are some explanatory texts on larger screens.

plurals
  1. POCython: "fatal error: numpy/arrayobject.h: No such file or directory"
    text
    copied!<p>I'm trying to speed up the answer <a href="https://stackoverflow.com/a/14469557/1658908">here</a> using Cython. I try to compile the code (after doing the <code>cygwinccompiler.py</code> hack explained <a href="https://stackoverflow.com/questions/6034390/compiling-with-cython-and-mingw-produces-gcc-error-unrecognized-command-line-o/6035864#6035864">here</a>), but get a <code>fatal error: numpy/arrayobject.h: No such file or directory...compilation terminated</code> error. Can anyone tell me if it's a problem with my code, or some esoteric subtlety with Cython?</p> <p>Below is my code. Thanks in advance:</p> <pre><code>import numpy as np import scipy as sp cimport numpy as np cimport cython cdef inline np.ndarray[np.int, ndim=1] fbincount(np.ndarray[np.int_t, ndim=1] x): cdef int m = np.amax(x)+1 cdef int n = x.size cdef unsigned int i cdef np.ndarray[np.int_t, ndim=1] c = np.zeros(m, dtype=np.int) for i in xrange(n): c[&lt;unsigned int&gt;x[i]] += 1 return c cdef packed struct Point: np.float64_t f0, f1 @cython.boundscheck(False) def sparsemaker(np.ndarray[np.float_t, ndim=2] X not None, np.ndarray[np.float_t, ndim=2] Y not None, np.ndarray[np.float_t, ndim=2] Z not None): cdef np.ndarray[np.float64_t, ndim=1] counts, factor cdef np.ndarray[np.int_t, ndim=1] row, col, repeats cdef np.ndarray[Point] indices cdef int x_, y_ _, row = np.unique(X, return_inverse=True); x_ = _.size _, col = np.unique(Y, return_inverse=True); y_ = _.size indices = np.rec.fromarrays([row,col]) _, repeats = np.unique(indices, return_inverse=True) counts = 1. / fbincount(repeats) Z.flat *= counts.take(repeats) return sp.sparse.csr_matrix((Z.flat,(row,col)), shape=(x_, y_)).toarray() </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload