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

Neal Becker ndbecker2@gmail....
Thu Jan 3 06:17:11 CST 2008


Robert Kern wrote:

> Neal Becker wrote:
>> Robert Kern wrote:
>> 
>>> 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)
>>>
>> 

It seems this also works?
z = empty([10], dtype=complex)
z.real = random.standard_normal(10)
z.imag = random.standard_normal(10)




More information about the SciPy-user mailing list