[SciPy-user] [newb] how to create arrays
Thu Jan 3 06:00:55 CST 2008
Robert Kern wrote:
> Anne Archibald wrote:
>> On 02/01/2008, Neal Becker <email@example.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
>>> 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(, dtype=complex)
> z.real[:] = random.standard_normal(10)
> z.imag[:] = random.standard_normal(10)
This is what I had in mind.
I guess there isn't something that could do this in a single step, something
z = random.standard_normal(10) + i * random.standard_normal(10)
More information about the SciPy-user