[Numpy-discussion] Compact way of performing array math with specified result type?

Russell E. Owen rowen@cesmail....
Fri Apr 27 16:17:34 CDT 2007

I often find myself doing simple math on sequences of numbers (which 
might or might not be numpy arrays) where I want the result (and thus 
the inputs) coerced to a particular data type.

I'd like to be able to say:

  numpy.divide(seq1, seq2, dtype=float)

but ufuncs don't allow on to specify a result type. So I do this instead:

  numpy.array(seq1, dtype=float) / numpy.array(seq2, dtype=float)

Is there a more compact solution (without having to create the result 
array first and supply it as an argument)?

-- Russell

More information about the Numpy-discussion mailing list