<br><br><div class="gmail_quote">On Tue, Feb 1, 2011 at 1:30 PM, John Salvatier <span dir="ltr"><<a href="mailto:jsalvati@u.washington.edu">jsalvati@u.washington.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

Have you thought about using cython to work with the numpy C-API (<a href="http://wiki.cython.org/tutorials/numpy#UsingtheNumpyCAPI" target="_blank">http://wiki.cython.org/tutorials/numpy#UsingtheNumpyCAPI</a>)? This will be fast, simple (you can mix and match Python and Cython). <div>


<br></div><div>As for your specific issue: you can simply cast to all the inputs to numpy arrays (using asarray <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.asarray.html" target="_blank">http://docs.scipy.org/doc/numpy/reference/generated/numpy.asarray.html</a>) to deal with scalars. This will make sure they get broadcast correctly.<div>

<div></div><div class="h5"><br></div></div></div></blockquote><div><br>Don't use "asarray" blindly!  Using asarray causes masked_arrays to become regular arrays.  If all of the operations in your function are vectorized already, then you are causing your function to unnecessarially break support for subclassed arrays like masked_arrays.<br>

<br>Use asanyarray() by default unless it has to be asarray().<br><br>Sorry for my rant.  I just love masked arrays too much...<br>Ben Root<br><br><br></div></div>