there are couple facilities for creating your own functions with ufunc-like semantics numpy frompyfunc accepts python function along with specification for the number of inputs and outputs for examplea simple function that adds element-wise would be specified asin [ ]def add_elements(xy)return in [ ]add_them np frompyfunc(add_elements in [ ]add_them(np arange( )np arange( )out[ ]array([ ]dtype=objectfunctions created using frompyfunc always return arrays of python objects which isn' very convenient fortunatelythere is an alternatebut slightly less featureful function numpy vectorize that is bit more intelligent about type inferencein [ ]add_them np vectorize(add_elementsotypes=[np float ]in [ ]add_them(np arange( )np arange( )out[ ]array( ]these functions provide way to create ufunc-like functionsbut they are very slow because they require python function call to compute each elementwhich is lot slower than numpy' -based ufunc loopsin [ ]arr randn( in [ ]%timeit add_them(arrarr loopsbest of ms per loop in [ ]%timeit np add(arrarr loopsbest of us per loop there are number of projects under way in the scientific python community to make it easier to define new ufuncs whose performance is closer to that of the built-in ones structured and record arrays you may have noticed up until now that ndarray is homogeneous data containerthat isit represents block of memory in which each element takes up the same number of bytesdetermined by the dtype on the surfacethis would appear to not allow you to represent heterogeneous or tabular-like data structured array is an ndarray in which each element can be thought of as representing struct in (hence the "structurednameor row in sql table with multiple named fieldsin [ ]dtype [(' 'np float )(' 'np int )in [ ]sarr np array([( )(np pi- )]dtype=dtype advanced numpy www it-ebooks info