<div dir="ltr">On Tue, Oct 29, 2013 at 4:47 PM, Henry Gomersall <<a href="mailto:heng@cantab.net">heng@cantab.net</a>> wrote:<br>><br>> Is there a way to extract the size of array that would be created by<br>> doing 1j*array?<br>

><br>> The problem I'm having is in creating an empty array to fill with<br>> complex values without knowing a priori what the input data type is.<br>><br>> For example, I have a real or int array `a`.<br>

><br>> I want to create an array `b` which can hold values from 1j*a in such a<br>> way that I don't need to compute those explicitly (because I only need<br>> parts of the array say), without upcasting (or indeed downcasting) the<br>

> result.<br>><br>> So if `a` was dtype 'float32`, `b` would be of dtype `complex64`. If `a`<br>> was `int64`, `b` would be of dtype `complex128` etc.<br><br>Quick and dirty:<br><br># Get a tiny array from `a` to test the dtype of its output when multiplied <br>

# by a complex float. It must be an array rather than a scalar since theĀ <div># casting rules are different for array*scalar and scalar*scalar.<br>dt = (a.flat[:2] * 1j).dtype<br>b = np.empty(shape, dtype=dt)<br><br>--<br>

Robert Kern</div></div>