[SciPy-user] [newb] how to create arrays

Robert Kern robert.kern@gmail....
Thu Jan 3 04:13:56 CST 2008

Anne Archibald wrote:
> On 02/01/2008, Neal Becker <ndbecker2@gmail.com> wrote:
>> How would I create a vector of complex random variables?
>> I'm thinking the best way is to create a complex vector, then
>> assign to the real and imag parts (using e.g., random.standard_normal).
>> I don't see any way to create an uninitialized array.  I guess I'd have to
>> use zeros?  Is there any way to avoid the wasted time of initializing just
>> to write over it?
> You can create an uninitialized array if you want to. But, from your
> question, you may well be thinking about your problem in the wrong
> way. If all you want to do is store a whole bunch of values you
> compute in a loop, use a python list.

In this case, he wouldn't be using a loop.

  from numpy import *

  z = empty([10], dtype=complex)
  z.real[:] = random.standard_normal(10)
  z.imag[:] = random.standard_normal(10)

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

More information about the SciPy-user mailing list