Why ufunc out arg has to be an ndarray?
![](https://secure.gravatar.com/avatar/f9ed6413b67cfa6ddc0a37675d9e065a.jpg?s=120&d=mm&r=g)
Jan. 8, 2025
11:21 p.m.
From time to time I find myself overwriting a python buffer with the output of a ufunc, for example like this: import array import numpy as np a = array.array('f', (1,1,1)) np.exp2(a, out=np.asarray(a)) assert a.tolist() == [2, 2, 2] Here I have to wrap `out=np.asarray(a)` because the more natural `np.exp2(a, out=a)` raises "TypeError: return arrays must be of ArrayType” In general, ufuncs are quite aggressive in utilizing the buffer protocol for input arguments. I was wondering, why are they so reluctant to do the same for the output argument? Is this a design choice? Efficiency? Legacy? Would be implementing `np.ufunc(a, out=a)` dangerous or cumbersome? Stefano
39
Age (days ago)
39
Last active (days ago)
0 comments
1 participants
participants (1)
-
Stefano Miccoli