On Tue, 19 Jul 2011 17:15:47 -0500, Chad Netzer wrote:
> On Tue, Jul 19, 2011 at 3:35 PM, Carlos Becker <carlosbec...@gmail.com>
[clip]
>> However, if I don't, I obtain this 4x penalty with numpy, even with the
>> 8092x8092 array. Would it be possible to do k = m - 0.5 and
>> pre-alllocate k such that python does not have to waste time on that?
> 
> I suspect the 4x penalty is related to the expression evaluation
> overhead (temporaries and copying), so hopefully numexpr() will help, or
> just remembering to use the in-place operators whenever appropriate.

Doubtful:

        k = m - 0.5

does here the same thing as

        k = np.empty_like(m)
        np.subtract(m, 0.5, out=k)

The memory allocation (empty_like and the subsequent deallocation)
costs essentially nothing, and there are no temporaries or copying
in `subtract`.

    ***

There's something else going on -- on my machine, the Numpy operation
runs exactly at the same speed as C, so this issue must have
a platform-dependent explanation.

-- 
Pauli Virtanen

_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to