[SciPy-User] getting started with ndarray

Keith Goodman kwgoodman at gmail.com
Wed May 5 22:58:47 EDT 2010


On Wed, May 5, 2010 at 7:44 PM, David Goldsmith <d.l.goldsmith at gmail.com> wrote:
> On Wed, May 5, 2010 at 7:28 PM, Victor Eijkhout <eijkhout at tacc.utexas.edu>
> wrote:
>>
>> On 2010/05/05, at 9:24 PM, Keith Goodman wrote:
>>
>> > Here's one way to create arrays:
>>
>> Thanks. Suppose I don't have the data yet, but I simple want to
>> allocate a, oh let's say, 5000x300x20 array?
>
>>>> import numpy as np
>>>> a = np.zeros((5000, 300, 20))
>>>> a.shape
> (5000L, 300L, 20L)
>
> IIRC, there's a quicker way if you don't need the array's values
> initialized, but I forget what it is.

Faster to computer, but slower to grok:

>> timeit np.zeros((5000, 300, 20))
10 loops, best of 3: 119 ms per loop
>> timeit np.empty((5000, 300, 20))
100000 loops, best of 3: 6.72 us per loop
>> timeit x = np.empty((5000, 300, 20)); x.fill(0.0)
10 loops, best of 3: 115 ms per loop



More information about the SciPy-User mailing list