1

Suppose I have an array A of dtype int32, and I want to cast it into float64. The standard way to do this (that I know) is A.astype('float64'). But this allocates a new array for the result. If I run this command repeatedly (with different arrays of the same shape), each time using the result and discarding it shortly after, then the overhead from these allocations can be non-negligible.
Suppose I pre-allocated an array B, with the same shape of A and of type float64. Is there a way to use the memory of B for the result of the casting, instead of allocating new memory each time? ufuncs and numpy.dot have an 'out' argument for this, but astpye does not.

2
  • 3
    B[...] = A? -- Commented Apr 2, 2018 at 8:33
  • Yes of course! Don't know why I missed this... Commented Apr 2, 2018 at 8:39

1 Answer 1

1

As Paul Panzer commented, this can be done simply by B[...] = A.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.