[SciPy-user] temporary copies for in-place array modification?
Mon Jul 28 11:47:58 CDT 2008
On Mon, Jul 28, 2008 at 11:48, Alan G Isaac <firstname.lastname@example.org> wrote:
> On Mon, 28 Jul 2008, Robert Kern apparently wrote:
>> Unfortunately, a temporary is unavoidable. If you modify `a` in-place,
>> you will mess up the computation. For example, we could try using the
>> third argument to the subtract() ufunc to place the results back into
>> In : import numpy
>> In : a = numpy.arange(1,7)
>> In : numpy.subtract(a[1:], a[:-1], a[1:])
>> Out: array([1, 2, 2, 3, 3])
> But he could work from the other end::
> >>> np.subtract(a[1:],a[:-1],a[:-1])
> array([1, 1, 1, 1, 1])
> As long as he can then use a[:-1] instead of a[1:].
"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